提交 97d7d3ac 编写于 作者: D dapan

Merge remote-tracking branch 'origin/3.0' into feature/scheduler

...@@ -25,6 +25,8 @@ if(${BUILD_TEST}) ...@@ -25,6 +25,8 @@ if(${BUILD_TEST})
enable_testing() enable_testing()
endif(${BUILD_TEST}) endif(${BUILD_TEST})
add_subdirectory(source) add_subdirectory(source)
add_subdirectory(tools)
add_subdirectory(tests)
# docs # docs
add_subdirectory(docs) add_subdirectory(docs)
......
...@@ -76,44 +76,14 @@ def pre_test(){ ...@@ -76,44 +76,14 @@ def pre_test(){
git fetch origin +refs/pull/${CHANGE_ID}/merge git fetch origin +refs/pull/${CHANGE_ID}/merge
git checkout -qf FETCH_HEAD git checkout -qf FETCH_HEAD
git clean -dfx git clean -dfx
'''
script {
if (env.CHANGE_TARGET == 'master') {
sh '''
cd ${WK}
git checkout master
'''
}
else if(env.CHANGE_TARGET == '2.0'){
sh '''
cd ${WK}
git checkout 2.0
'''
}
else if(env.CHANGE_TARGET == '3.0'){
sh '''
cd ${WK}
git checkout 3.0
'''
}
else{
sh '''
cd ${WK}
git checkout develop
'''
}
}
sh '''
cd ${WK}
git pull >/dev/null
git clean -dfx git clean -dfx
export TZ=Asia/Harbin export TZ=Asia/Harbin
date date
mkdir debug mkdir debug
cd debug cd debug
cmake .. > /dev/null cmake .. > /dev/null
make > /dev/null make -j4> /dev/null
make install > /dev/null
''' '''
return 1 return 1
...@@ -124,11 +94,11 @@ pipeline { ...@@ -124,11 +94,11 @@ pipeline {
options { skipDefaultCheckout() } options { skipDefaultCheckout() }
environment{ environment{
WK = '/var/lib/jenkins/workspace/TDinternal' WK = '/var/lib/jenkins/workspace/TDinternal'
WKC= '/var/lib/jenkins/workspace/TDinternal/community' WKC= '/var/lib/jenkins/workspace/TDengine'
} }
stages { stages {
stage('pre_build'){ stage('pre_build'){
agent{label 'master'} agent{label 'slave3_0'}
options { skipDefaultCheckout() } options { skipDefaultCheckout() }
when { when {
changeRequest() changeRequest()
......
...@@ -80,8 +80,8 @@ typedef enum { ...@@ -80,8 +80,8 @@ typedef enum {
typedef struct taosField { typedef struct taosField {
char name[65]; char name[65];
uint8_t type; int8_t type;
int16_t bytes; int32_t bytes;
} TAOS_FIELD; } TAOS_FIELD;
#ifdef _TD_GO_DLL_ #ifdef _TD_GO_DLL_
......
...@@ -50,8 +50,7 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_CONSUME, "mq-consume" ) ...@@ -50,8 +50,7 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_CONSUME, "mq-consume" )
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_QUERY, "mq-query" ) 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_CONNECT, "mq-connect" )
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_DISCONNECT, "mq-disconnect" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_DISCONNECT, "mq-disconnect" )
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_ACK, "mq-ack" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_SET, "mq-set" )
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_MQ_RESET, "mq-reset" )
// message from client to mnode // message from client to mnode
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONNECT, "connect" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CONNECT, "connect" )
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_ACCT, "create-acct" ) TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_ACCT, "create-acct" )
...@@ -571,14 +570,13 @@ typedef struct { ...@@ -571,14 +570,13 @@ typedef struct {
} SRetrieveTableMsg; } SRetrieveTableMsg;
typedef struct SRetrieveTableRsp { typedef struct SRetrieveTableRsp {
int32_t numOfRows;
int64_t offset; // updated offset value for multi-vnode projection query
int64_t useconds; int64_t useconds;
int8_t completed; // all results are returned to client int8_t completed; // all results are returned to client
int8_t precision; int8_t precision;
int8_t compressed; int8_t compressed;
int8_t reserved;
int32_t compLen; int32_t compLen;
int32_t numOfRows;
char data[]; char data[];
} SRetrieveTableRsp; } SRetrieveTableRsp;
...@@ -785,11 +783,7 @@ typedef struct { ...@@ -785,11 +783,7 @@ typedef struct {
} SAuthVnodeMsg; } SAuthVnodeMsg;
typedef struct { typedef struct {
char name[TSDB_TABLE_FNAME_LEN]; int32_t vgId;
} SStbInfoMsg;
typedef struct {
SMsgHead msgHead;
char tableFname[TSDB_TABLE_FNAME_LEN]; char tableFname[TSDB_TABLE_FNAME_LEN];
} STableInfoMsg; } STableInfoMsg;
...@@ -801,10 +795,6 @@ typedef struct { ...@@ -801,10 +795,6 @@ typedef struct {
char tableNames[]; char tableNames[];
} SMultiTableInfoMsg; } SMultiTableInfoMsg;
typedef struct SSTableVgroupMsg {
int32_t numOfTables;
} SSTableVgroupMsg, SSTableVgroupRspMsg;
typedef struct SVgroupInfo { typedef struct SVgroupInfo {
int32_t vgId; int32_t vgId;
uint32_t hashBegin; uint32_t hashBegin;
...@@ -814,12 +804,6 @@ typedef struct SVgroupInfo { ...@@ -814,12 +804,6 @@ typedef struct SVgroupInfo {
SEpAddrMsg epAddr[TSDB_MAX_REPLICA]; SEpAddrMsg epAddr[TSDB_MAX_REPLICA];
} SVgroupInfo; } SVgroupInfo;
typedef struct SVgroupListRspMsg {
int32_t vgroupNum;
int32_t vgroupVersion;
SVgroupInfo vgroupInfo[];
} SVgroupListRspMsg;
typedef struct { typedef struct {
int32_t vgId; int32_t vgId;
int8_t numOfEps; int8_t numOfEps;
...@@ -841,8 +825,8 @@ typedef struct { ...@@ -841,8 +825,8 @@ typedef struct {
int8_t update; int8_t update;
int32_t sversion; int32_t sversion;
int32_t tversion; int32_t tversion;
uint64_t tuid;
uint64_t suid; uint64_t suid;
uint64_t tuid;
int32_t vgId; int32_t vgId;
SSchema pSchema[]; SSchema pSchema[];
} STableMetaMsg; } STableMetaMsg;
......
...@@ -62,7 +62,7 @@ enum { ...@@ -62,7 +62,7 @@ enum {
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CFG_DNODE, "cfg-dnode" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CFG_DNODE, "cfg-dnode" )
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CFG_MNODE, "cfg-mnode" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_CFG_MNODE, "cfg-mnode" )
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_SHOW, "show" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_SHOW, "show" )
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_RETRIEVE, "retrieve" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_RETRIEVE_MNODE, "retrieve" )
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_KILL_QUERY, "kill-query" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_KILL_QUERY, "kill-query" )
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_KILL_STREAM, "kill-stream" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_KILL_STREAM, "kill-stream" )
TSDB_DEFINE_SQL_TYPE( TSDB_SQL_KILL_CONNECTION, "kill-connection" ) TSDB_DEFINE_SQL_TYPE( TSDB_SQL_KILL_CONNECTION, "kill-connection" )
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#ifndef TDENGINE_TNAME_H #ifndef TDENGINE_TNAME_H
#define TDENGINE_TNAME_H #define TDENGINE_TNAME_H
#include "taosmsg.h" //#include "taosmsg.h"
#define TSDB_DB_NAME_T 1 #define TSDB_DB_NAME_T 1
#define TSDB_TABLE_NAME_T 2 #define TSDB_TABLE_NAME_T 2
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
typedef struct SName { typedef struct SName {
uint8_t type; //db_name_t, table_name_t uint8_t type; //db_name_t, table_name_t
char acctId[TSDB_ACCT_ID_LEN]; int32_t acctId;
char dbname[TSDB_DB_NAME_LEN]; char dbname[TSDB_DB_NAME_LEN];
char tname[TSDB_TABLE_NAME_LEN]; char tname[TSDB_TABLE_NAME_LEN];
} SName; } SName;
...@@ -38,7 +38,7 @@ int32_t tNameLen(const SName* name); ...@@ -38,7 +38,7 @@ int32_t tNameLen(const SName* name);
SName* tNameDup(const SName* name); SName* tNameDup(const SName* name);
bool tIsValidName(const SName* name); bool tNameIsValid(const SName* name);
const char* tNameGetTableName(const SName* name); const char* tNameGetTableName(const SName* name);
...@@ -50,14 +50,10 @@ bool tNameIsEmpty(const SName* name); ...@@ -50,14 +50,10 @@ bool tNameIsEmpty(const SName* name);
void tNameAssign(SName* dst, const SName* src); void tNameAssign(SName* dst, const SName* src);
int32_t tNameFromString(SName* dst, const char* str, uint32_t type); int32_t tNameSetDbName(SName* dst, int32_t acctId, const char* dbName, size_t nameLen);
int32_t tNameSetAcctId(SName* dst, const char* acct);
SSchema* tGetTbnameColumnSchema(); int32_t tNameFromString(SName* dst, const char* str, uint32_t type);
#if 0 int32_t tNameSetAcctId(SName* dst, int32_t acctId);
int32_t tNameSetDbName(SName* dst, const char* acct, SToken* dbToken);
#endif
#endif // TDENGINE_TNAME_H #endif // TDENGINE_TNAME_H
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#ifndef _TD_META_H_ #ifndef _TD_META_H_
#define _TD_META_H_ #define _TD_META_H_
#include "mallocator.h"
#include "os.h" #include "os.h"
#include "trow.h" #include "trow.h"
...@@ -71,7 +72,7 @@ typedef struct STbCfg { ...@@ -71,7 +72,7 @@ typedef struct STbCfg {
} STbCfg; } STbCfg;
// SMeta operations // SMeta operations
SMeta *metaOpen(const char *path, const SMetaCfg *pOptions); SMeta *metaOpen(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF);
void metaClose(SMeta *pMeta); void metaClose(SMeta *pMeta);
void metaRemove(const char *path); void metaRemove(const char *path);
int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg); int metaCreateTable(SMeta *pMeta, STbCfg *pTbCfg);
...@@ -79,8 +80,8 @@ int metaDropTable(SMeta *pMeta, tb_uid_t uid); ...@@ -79,8 +80,8 @@ int metaDropTable(SMeta *pMeta, tb_uid_t uid);
int metaCommit(SMeta *pMeta); int metaCommit(SMeta *pMeta);
// Options // Options
void metaOptionsInit(SMetaCfg *pOptions); void metaOptionsInit(SMetaCfg *pMetaCfg);
void metaOptionsClear(SMetaCfg *pOptions); void metaOptionsClear(SMetaCfg *pMetaCfg);
// STbCfg // STbCfg
#define META_INIT_STB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) \ #define META_INIT_STB_CFG(NAME, TTL, KEEP, SUID, PSCHEMA, PTAGSCHEMA) \
......
...@@ -62,10 +62,10 @@ typedef struct TmqDisconnectRsp { ...@@ -62,10 +62,10 @@ typedef struct TmqDisconnectRsp {
int8_t status; int8_t status;
} TmqDisconnectRsp; } TmqDisconnectRsp;
typedef struct TmqConsumeReq { typedef struct STqConsumeReq {
TmqMsgHead head; TmqMsgHead head;
TmqAcks acks; TmqAcks acks;
} TmqConsumeReq; } STqConsumeReq;
typedef struct TmqMsgContent { typedef struct TmqMsgContent {
int64_t topicId; int64_t topicId;
...@@ -73,11 +73,11 @@ typedef struct TmqMsgContent { ...@@ -73,11 +73,11 @@ typedef struct TmqMsgContent {
char msg[]; char msg[];
} TmqMsgContent; } TmqMsgContent;
typedef struct TmqConsumeRsp { typedef struct STqConsumeRsp {
TmqMsgHead head; TmqMsgHead head;
int64_t bodySize; int64_t bodySize;
TmqMsgContent msgs[]; TmqMsgContent msgs[];
} TmqConsumeRsp; } STqConsumeRsp;
typedef struct TmqSubscribeReq { typedef struct TmqSubscribeReq {
TmqMsgHead head; TmqMsgHead head;
...@@ -261,13 +261,14 @@ typedef struct STQ { ...@@ -261,13 +261,14 @@ typedef struct STQ {
// open in each vnode // open in each vnode
STQ* tqOpen(const char* path, STqCfg* tqConfig, STqLogReader* tqLogReader, SMemAllocatorFactory* allocFac); STQ* tqOpen(const char* path, STqCfg* tqConfig, STqLogReader* tqLogReader, SMemAllocatorFactory* allocFac);
void tqDestroy(STQ*); void tqClose(STQ*);
// void* will be replace by a msg type // void* will be replace by a msg type
int tqPushMsg(STQ*, void* msg, int64_t version); int tqPushMsg(STQ*, void* msg, int64_t version);
int tqCommit(STQ*); int tqCommit(STQ*);
int tqSetCursor(STQ*, void* msg);
int tqConsume(STQ*, TmqConsumeReq*); int tqConsume(STQ*, STqConsumeReq*);
STqGroupHandle* tqGetGroupHandle(STQ*, int64_t cId); STqGroupHandle* tqGetGroupHandle(STQ*, int64_t cId);
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#ifndef _TD_TSDB_H_ #ifndef _TD_TSDB_H_
#define _TD_TSDB_H_ #define _TD_TSDB_H_
#include "mallocator.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
...@@ -25,7 +27,7 @@ typedef struct STsdb STsdb; ...@@ -25,7 +27,7 @@ typedef struct STsdb STsdb;
typedef struct STsdbCfg STsdbCfg; typedef struct STsdbCfg STsdbCfg;
// STsdb // STsdb
STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbCfg); STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF);
void tsdbClose(STsdb *); void tsdbClose(STsdb *);
void tsdbRemove(const char *path); void tsdbRemove(const char *path);
int tsdbInsertData(STsdb *pTsdb, SSubmitMsg *pMsg); int tsdbInsertData(STsdb *pTsdb, SSubmitMsg *pMsg);
......
...@@ -34,6 +34,13 @@ enum OPERATOR_TYPE_E { ...@@ -34,6 +34,13 @@ enum OPERATOR_TYPE_E {
OP_TotalNum OP_TotalNum
}; };
enum DATASINK_TYPE_E {
DSINK_Unknown,
DSINK_Dispatch,
DSINK_Insert,
DSINK_TotalNum
};
struct SEpSet; struct SEpSet;
struct SQueryStmtInfo; struct SQueryStmtInfo;
...@@ -49,6 +56,22 @@ typedef struct SQueryNodeBasicInfo { ...@@ -49,6 +56,22 @@ typedef struct SQueryNodeBasicInfo {
const char *name; // operator name const char *name; // operator name
} SQueryNodeBasicInfo; } 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
} SDataInserter;
typedef struct SPhyNode { typedef struct SPhyNode {
SQueryNodeBasicInfo info; SQueryNodeBasicInfo info;
SArray *pTargets; // target list to be computed or scanned at this node SArray *pTargets; // target list to be computed or scanned at this node
...@@ -85,7 +108,7 @@ typedef struct SProjectPhyNode { ...@@ -85,7 +108,7 @@ typedef struct SProjectPhyNode {
typedef struct SExchangePhyNode { typedef struct SExchangePhyNode {
SPhyNode node; SPhyNode node;
uint64_t srcTemplateId; // template id of datasource suplans uint64_t srcTemplateId; // template id of datasource suplans
SArray *pSourceEpSet; // SEpSet, scheduler fill by calling qSetSuplanExecutionNode SArray *pSrcEndPoints; // SEpAddrMsg, scheduler fill by calling qSetSuplanExecutionNode
} SExchangePhyNode; } SExchangePhyNode;
typedef struct SSubplanId { typedef struct SSubplanId {
...@@ -115,22 +138,29 @@ typedef struct SQueryDag { ...@@ -115,22 +138,29 @@ typedef struct SQueryDag {
*/ */
int32_t qCreateQueryDag(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* pQnode, struct SQueryDag** pDag); int32_t qCreateQueryDag(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* pQnode, struct SQueryDag** pDag);
int32_t qSetSuplanExecutionNode(SArray* subplans, SArray* nodes); // Set datasource of this subplan, multiple calls may be made to a subplan.
// @subplan subplan to be schedule
// @templateId templateId of a group of datasource subplans of this @subplan
// @eps Execution location of this group of datasource subplans, is an array of SEpAddr structures
int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SArray* eps);
int32_t qExplainQuery(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* pQnode, char** str); int32_t qExplainQuery(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* pQnode, char** str);
/** /**
* Convert to subplan to string for the scheduler to send to the executor * Convert to subplan to string for the scheduler to send to the executor
*/ */
int32_t qSubPlanToString(struct SSubplan *pPhyNode, char** str); int32_t qSubPlanToString(const SSubplan* subplan, char** str);
int32_t qStringToSubplan(const char* str, SSubplan** subplan);
void qDestroySubplan(SSubplan* pSubplan);
/** /**
* Destroy the physical plan. * Destroy the physical plan.
* @param pQueryPhyNode * @param pQueryPhyNode
* @return * @return
*/ */
void qDestroyQueryDag(struct SQueryDag* pDag); void qDestroyQueryDag(SQueryDag* pDag);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -24,8 +24,6 @@ extern "C" { ...@@ -24,8 +24,6 @@ extern "C" {
#include "thash.h" #include "thash.h"
#include "tlog.h" #include "tlog.h"
typedef SVgroupListRspMsg SVgroupListInfo;
typedef struct STableComInfo { typedef struct STableComInfo {
uint8_t numOfTags; // the number of tags in schema uint8_t numOfTags; // the number of tags in schema
uint8_t precision; // the number of precision uint8_t precision; // the number of precision
...@@ -83,12 +81,14 @@ typedef struct STableMetaOutput { ...@@ -83,12 +81,14 @@ typedef struct STableMetaOutput {
STableMeta *tbMeta; STableMeta *tbMeta;
} STableMetaOutput; } STableMetaOutput;
bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags);
extern int32_t (*queryBuildMsg[TSDB_MSG_TYPE_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen); 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); extern int32_t (*queryProcessMsgRsp[TSDB_MSG_TYPE_MAX])(void* output, char *msg, int32_t msgSize);
SSchema* tGetTbnameColumnSchema();
extern void msgInit(); extern void msgInit();
extern int32_t qDebugFlag; extern int32_t qDebugFlag;
#define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", qDebugFlag, __VA_ARGS__); }} while(0) #define qFatal(...) do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", qDebugFlag, __VA_ARGS__); }} while(0)
......
...@@ -46,6 +46,7 @@ extern "C" { ...@@ -46,6 +46,7 @@ extern "C" {
#include <math.h> #include <math.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/utsname.h>
#include <dirent.h> #include <dirent.h>
#include <unistd.h> #include <unistd.h>
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
extern "C" { extern "C" {
#endif #endif
#include "os.h"
#define TSDB_LOCALE_LEN 64 #define TSDB_LOCALE_LEN 64
#define TSDB_TIMEZONE_LEN 96 #define TSDB_TIMEZONE_LEN 96
...@@ -57,11 +59,11 @@ char * taosGetCmdlineByPID(int pid); ...@@ -57,11 +59,11 @@ char * taosGetCmdlineByPID(int pid);
void taosSetCoreDump(bool enable); void taosSetCoreDump(bool enable);
typedef struct { typedef struct {
const char *sysname; char sysname[_UTSNAME_MACHINE_LENGTH];
const char *nodename; char nodename[_UTSNAME_MACHINE_LENGTH];
const char *release; char release[_UTSNAME_MACHINE_LENGTH];
const char *version; char version[_UTSNAME_MACHINE_LENGTH];
const char *machine; char machine[_UTSNAME_MACHINE_LENGTH];
} SysNameInfo; } SysNameInfo;
SysNameInfo taosGetSysNameInfo(); SysNameInfo taosGetSysNameInfo();
......
...@@ -22,23 +22,28 @@ ...@@ -22,23 +22,28 @@
extern "C" { extern "C" {
#endif #endif
typedef struct SMemAllocator SMemAllocator; // Memory allocator
typedef struct SMemAllocatorFactory SMemAllocatorFactory; #define TD_MEM_ALCT(TYPE) \
struct { \
struct SMemAllocator { void *(*malloc_)(struct TYPE *, uint64_t size); \
void (*free_)(struct TYPE *, void *ptr); \
}
#define TD_MA_MALLOC_FUNC(TMA) (TMA)->malloc_
#define TD_MA_FREE_FUNC(TMA) (TMA)->free_
#define TD_MA_MALLOC(TMA, SIZE) (*((TMA)->malloc_))(TMA, (SIZE))
#define TD_MA_FREE(TMA, PTR) (*((TMA)->free_))(TMA, (PTR))
typedef struct SMemAllocator {
void *impl; void *impl;
void *(*malloc)(SMemAllocator *, uint64_t size); TD_MEM_ALCT(SMemAllocator);
void *(*calloc)(SMemAllocator *, uint64_t nmemb, uint64_t size); } SMemAllocator;
void *(*realloc)(SMemAllocator *, void *ptr, uint64_t size);
void (*free)(SMemAllocator *, void *ptr); typedef struct SMemAllocatorFactory {
uint64_t (*usage)(SMemAllocator *);
};
struct SMemAllocatorFactory {
void *impl; void *impl;
SMemAllocator *(*create)(SMemAllocatorFactory *); SMemAllocator *(*create)(struct SMemAllocatorFactory *);
void (*destroy)(SMemAllocatorFactory *, SMemAllocator *); void (*destroy)(struct SMemAllocatorFactory *, SMemAllocator *);
}; } SMemAllocatorFactory;
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -206,44 +206,28 @@ int32_t* taosGetErrno(); ...@@ -206,44 +206,28 @@ int32_t* taosGetErrno();
#define TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0392) #define TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE TAOS_DEF_ERROR_CODE(0, 0x0392)
// mnode-stable // mnode-stable
#define TSDB_CODE_MND_STB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360) #define TSDB_CODE_MND_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A0)
#define TSDB_CODE_MND_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360) #define TSDB_CODE_MND_STB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A1)
#define TSDB_CODE_MND_STB_INVALID_IGEXIST TAOS_DEF_ERROR_CODE(0, 0x0360) #define TSDB_CODE_MND_TOO_MANY_STBS TAOS_DEF_ERROR_CODE(0, 0x03A2)
#define TSDB_CODE_MND_STB_INVALID_COLS_NUM TAOS_DEF_ERROR_CODE(0, 0x0360) #define TSDB_CODE_MND_INVALID_STB TAOS_DEF_ERROR_CODE(0, 0x03A3)
#define TSDB_CODE_MND_STB_INVALID_TAGS_NUM TAOS_DEF_ERROR_CODE(0, 0x0360) #define TSDB_CODE_MND_INVALID_STB_OPTION TAOS_DEF_ERROR_CODE(0, 0x03A4)
#define TSDB_CODE_MND_STB_INVALID_COL_TYPE TAOS_DEF_ERROR_CODE(0, 0x0360) #define TSDB_CODE_MND_STB_OPTION_UNCHNAGED TAOS_DEF_ERROR_CODE(0, 0x03A5)
#define TSDB_CODE_MND_STB_INVALID_COL_ID TAOS_DEF_ERROR_CODE(0, 0x0360) #define TSDB_CODE_MND_TOO_MANY_TAGS TAOS_DEF_ERROR_CODE(0, 0x03A6)
#define TSDB_CODE_MND_STB_INVALID_COL_BYTES TAOS_DEF_ERROR_CODE(0, 0x0360) #define TSDB_CODE_MND_TAG_ALREAY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A7)
#define TSDB_CODE_MND_STB_INVALID_COL_NAME TAOS_DEF_ERROR_CODE(0, 0x0360) #define TSDB_CODE_MND_TAG_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A8)
#define TSDB_CODE_MND_TOO_MANY_COLUMNS TAOS_DEF_ERROR_CODE(0, 0x03A9)
#define TSDB_CODE_MND_COLUMN_ALREAY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AA)
#define TSDB_CODE_MND_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0361) //"Table name too long") #define TSDB_CODE_MND_COLUMN_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03AB)
#define TSDB_CODE_MND_INVALID_TABLE_NAME TAOS_DEF_ERROR_CODE(0, 0x0362) //"Table does not exist") #define TSDB_CODE_MND_EXCEED_MAX_ROW_BYTES TAOS_DEF_ERROR_CODE(0, 0x03AC)
#define TSDB_CODE_MND_INVALID_TABLE_TYPE TAOS_DEF_ERROR_CODE(0, 0x0363) //"Invalid table type in tsdb")
#define TSDB_CODE_MND_TOO_MANY_TAGS TAOS_DEF_ERROR_CODE(0, 0x0364) //"Too many tags") // mnode-func
#define TSDB_CODE_MND_TOO_MANY_COLUMNS TAOS_DEF_ERROR_CODE(0, 0x0365) //"Too many columns") #define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03C0)
#define TSDB_CODE_MND_TOO_MANY_TIMESERIES TAOS_DEF_ERROR_CODE(0, 0x0366) //"Too many time series") #define TSDB_CODE_MND_FUNC_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x03C1)
#define TSDB_CODE_MND_NOT_SUPER_TABLE TAOS_DEF_ERROR_CODE(0, 0x0367) //"Not super table") // operation only available for super table #define TSDB_CODE_MND_INVALID_FUNC TAOS_DEF_ERROR_CODE(0, 0x03C2)
#define TSDB_CODE_MND_COL_NAME_TOO_LONG TAOS_DEF_ERROR_CODE(0, 0x0368) //"Tag name too long") #define TSDB_CODE_MND_INVALID_FUNC_NAME TAOS_DEF_ERROR_CODE(0, 0x03C3)
#define TSDB_CODE_MND_TAG_ALREAY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0369) //"Tag already exists") #define TSDB_CODE_MND_INVALID_FUNC_COMMENT TAOS_DEF_ERROR_CODE(0, 0x03C4)
#define TSDB_CODE_MND_TAG_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x036A) //"Tag does not exist") #define TSDB_CODE_MND_INVALID_FUNC_CODE TAOS_DEF_ERROR_CODE(0, 0x03C5)
#define TSDB_CODE_MND_FIELD_ALREAY_EXIST TAOS_DEF_ERROR_CODE(0, 0x036B) //"Field already exists") #define TSDB_CODE_MND_INVALID_FUNC_BUFSIZE TAOS_DEF_ERROR_CODE(0, 0x03C6)
#define TSDB_CODE_MND_FIELD_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x036C) //"Field does not exist")
#define TSDB_CODE_MND_INVALID_STABLE_NAME TAOS_DEF_ERROR_CODE(0, 0x036D) //"Super table does not exist")
#define TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG TAOS_DEF_ERROR_CODE(0, 0x036E) //"Invalid create table message")
#define TSDB_CODE_MND_EXCEED_MAX_ROW_BYTES TAOS_DEF_ERROR_CODE(0, 0x036F) //"Exceed max row bytes")
#define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0370)
#define TSDB_CODE_MND_FUNC_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0371)
#define TSDB_CODE_MND_INVALID_FUNC TAOS_DEF_ERROR_CODE(0, 0x0372)
#define TSDB_CODE_MND_INVALID_FUNC_NAME TAOS_DEF_ERROR_CODE(0, 0x0373)
#define TSDB_CODE_MND_INVALID_FUNC_COMMENT TAOS_DEF_ERROR_CODE(0, 0x0374)
#define TSDB_CODE_MND_INVALID_FUNC_CODE TAOS_DEF_ERROR_CODE(0, 0x0375)
#define TSDB_CODE_MND_INVALID_FUNC_BUFSIZE TAOS_DEF_ERROR_CODE(0, 0x0376)
#define TSDB_CODE_MND_INVALID_TAG_LENGTH TAOS_DEF_ERROR_CODE(0, 0x0376) //"invalid tag length")
#define TSDB_CODE_MND_INVALID_COLUMN_LENGTH TAOS_DEF_ERROR_CODE(0, 0x0377) //"invalid column length")
// dnode // dnode
#define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400) #define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0400)
......
...@@ -235,6 +235,7 @@ do { \ ...@@ -235,6 +235,7 @@ do { \
#define TSDB_MAX_VNODES 512 #define TSDB_MAX_VNODES 512
#define TSDB_MIN_VNODES_PER_DB 1 #define TSDB_MIN_VNODES_PER_DB 1
#define TSDB_MAX_VNODES_PER_DB 4096 #define TSDB_MAX_VNODES_PER_DB 4096
#define TSDB_DEFAULT_VN_PER_DB 2
#define TSDB_DNODE_ROLE_ANY 0 #define TSDB_DNODE_ROLE_ANY 0
#define TSDB_DNODE_ROLE_MGMT 1 #define TSDB_DNODE_ROLE_MGMT 1
......
/*
* 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_UTIL_TDLIST_H_
#define _TD_UTIL_TDLIST_H_
#ifdef __cplusplus
extern "C" {
#endif
// Single linked list
#define TD_SLIST_NODE(TYPE) \
struct { \
struct TYPE *sl_next_; \
}
#define TD_SLIST(TYPE) \
struct { \
struct TYPE *sl_head_; \
int sl_neles_; \
}
#define TD_SLIST_HEAD(sl) ((sl)->sl_head_)
#define TD_SLIST_NELES(sl) ((sl)->sl_neles_)
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
#define tSListInit(sl) \
do { \
(sl)->sl_head_ = NULL; \
(sl)->sl_neles_ = 0; \
} while (0)
#define tSListPush(sl, sln) \
do { \
TD_SLIST_NODE_NEXT(sln) = TD_SLIST_HEAD(sl); \
TD_SLIST_HEAD(sl) = (sln); \
TD_SLIST_NELES(sl) += 1; \
} while (0)
#define tSListPop(sl) \
do { \
TD_SLIST_HEAD(sl) = TD_SLIST_NODE_NEXT(TD_SLIST_HEAD(sl)); \
TD_SLIST_NELES(sl) -= 1; \
} while (0)
// Double linked list
#define TD_DLIST_NODE(TYPE) \
struct { \
struct TYPE *dl_prev_; \
struct TYPE *dl_next_; \
}
#define TD_DLIST(TYPE) \
struct { \
struct TYPE *dl_head_; \
struct TYPE *dl_tail_; \
int dl_neles_; \
}
#define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_)
#define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_)
#define TD_DLIST_HEAD(dl) ((dl)->dl_head_)
#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_)
#define TD_DLIST_NELES(dl) ((dl)->dl_neles_)
#define tDListInit(dl) \
do { \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = NULL; \
TD_DLIST_NELES(dl) = 0; \
} while (0)
#define tDListAppend(dl, dln) \
do { \
if (TD_DLIST_HEAD(dl) == NULL) { \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
} else { \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_TAIL(dl); \
TD_DLIST_NODE_NEXT(dln) = NULL; \
TD_DLIST_NODE_NEXT(TD_DLIST_TAIL(dl)) = (dln); \
TD_DLIST_TAIL(dl) = (dln); \
} \
TD_DLIST_NELES(dl) += 1; \
} while (0)
#define tDListPrepend(dl, dln) \
do { \
if (TD_DLIST_HEAD(dl) == NULL) { \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
} else { \
TD_DLIST_NODE_PREV(dln) = NULL; \
TD_DLIST_NODE_NEXT(dln) = TD_DLIST_HEAD(dl); \
TD_DLIST_NODE_PREV(TD_DLIST_HEAD(dl)) = (dln); \
TD_DLIST_HEAD(dl) = (dln); \
} \
TD_DLIST_NELES(dl) += 1; \
} while (0)
#define tDListPop(dl, dln) \
do { \
if (TD_DLIST_HEAD(dl) == (dln)) { \
TD_DLIST_HEAD(dl) = TD_DLIST_NODE_NEXT(dln); \
} \
if (TD_DLIST_TAIL(dl) == (dln)) { \
TD_DLIST_TAIL(dl) = TD_DLIST_NODE_PREV(dln); \
} \
if (TD_DLIST_NODE_PREV(dln) != NULL) { \
TD_DLIST_NODE_NEXT(TD_DLIST_NODE_PREV(dln)) = TD_DLIST_NODE_NEXT(dln); \
} \
if (TD_DLIST_NODE_NEXT(dln) != NULL) { \
TD_DLIST_NODE_PREV(TD_DLIST_NODE_NEXT(dln)) = TD_DLIST_NODE_PREV(dln); \
} \
TD_DLIST_NELES(dl) -= 1; \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
} while (0)
#if 0
// List iterator
#define TD_LIST_FITER 0
#define TD_LIST_BITER 1
#define TD_LIST_ITER(S) \
struct { \
int it_dir_; \
S * it_next_; \
S * it_ptr_; \
TD_DLIST(S) * it_list_; \
}
#define tlistIterInit(it, l, dir) \
(it)->it_dir_ = (dir); \
(it)->it_list_ = l; \
if ((dir) == TD_LIST_FITER) { \
(it)->it_next_ = (l)->dl_head_; \
} else { \
(it)->it_next_ = (l)->dl_tail_; \
}
#define tlistIterNext(it) \
({ \
(it)->it_ptr_ = (it)->it_next_; \
if ((it)->it_next_ != NULL) { \
if ((it)->it_dir_ == TD_LIST_FITER) { \
(it)->it_next_ = (it)->it_next_->next_; \
} else { \
(it)->it_next_ = (it)->it_next_->prev_; \
} \
} \
(it)->it_ptr_; \
})
#endif
#ifdef __cplusplus
}
#endif
#endif /*_TD_UTIL_TDLIST_H_*/
\ No newline at end of file
...@@ -19,18 +19,123 @@ ...@@ -19,18 +19,123 @@
extern "C" { extern "C" {
#endif #endif
// Single linked list ================
#define TD_SLIST_NODE(TYPE) \
struct { \
struct TYPE *sl_next_; \
}
#define TD_SLIST(TYPE) \
struct { \
struct TYPE *sl_head_; \
int sl_neles_; \
}
#define TD_SLIST_HEAD(sl) ((sl)->sl_head_)
#define TD_SLIST_NELES(sl) ((sl)->sl_neles_)
#define TD_SLIST_NODE_NEXT(sln) ((sln)->sl_next_)
#define TD_SLIST_INIT(sl) \
do { \
(sl)->sl_head_ = NULL; \
(sl)->sl_neles_ = 0; \
} while (0)
#define TD_SLIST_PUSH(sl, sln) \
do { \
TD_SLIST_NODE_NEXT(sln) = TD_SLIST_HEAD(sl); \
TD_SLIST_HEAD(sl) = (sln); \
TD_SLIST_NELES(sl) += 1; \
} while (0)
#define TD_SLIST_POP(sl) \
do { \
TD_SLIST_HEAD(sl) = TD_SLIST_NODE_NEXT(TD_SLIST_HEAD(sl)); \
TD_SLIST_NELES(sl) -= 1; \
} while (0)
// Double linked list ================
#define TD_DLIST_NODE(TYPE) \
struct { \
struct TYPE *dl_prev_; \
struct TYPE *dl_next_; \
}
#define TD_DLIST(TYPE) \
struct { \
struct TYPE *dl_head_; \
struct TYPE *dl_tail_; \
int dl_neles_; \
}
#define TD_DLIST_NODE_PREV(dln) ((dln)->dl_prev_)
#define TD_DLIST_NODE_NEXT(dln) ((dln)->dl_next_)
#define TD_DLIST_HEAD(dl) ((dl)->dl_head_)
#define TD_DLIST_TAIL(dl) ((dl)->dl_tail_)
#define TD_DLIST_NELES(dl) ((dl)->dl_neles_)
#define TD_DLIST_INIT(dl) \
do { \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = NULL; \
TD_DLIST_NELES(dl) = 0; \
} while (0)
#define TD_DLIST_APPEND(dl, dln) \
do { \
if (TD_DLIST_HEAD(dl) == NULL) { \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
} else { \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_TAIL(dl); \
TD_DLIST_NODE_NEXT(dln) = NULL; \
TD_DLIST_NODE_NEXT(TD_DLIST_TAIL(dl)) = (dln); \
TD_DLIST_TAIL(dl) = (dln); \
} \
TD_DLIST_NELES(dl) += 1; \
} while (0)
#define TD_DLIST_PREPEND(dl, dln) \
do { \
if (TD_DLIST_HEAD(dl) == NULL) { \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
TD_DLIST_HEAD(dl) = TD_DLIST_TAIL(dl) = (dln); \
} else { \
TD_DLIST_NODE_PREV(dln) = NULL; \
TD_DLIST_NODE_NEXT(dln) = TD_DLIST_HEAD(dl); \
TD_DLIST_NODE_PREV(TD_DLIST_HEAD(dl)) = (dln); \
TD_DLIST_HEAD(dl) = (dln); \
} \
TD_DLIST_NELES(dl) += 1; \
} while (0)
#define TD_DLIST_POP(dl, dln) \
do { \
if (TD_DLIST_HEAD(dl) == (dln)) { \
TD_DLIST_HEAD(dl) = TD_DLIST_NODE_NEXT(dln); \
} \
if (TD_DLIST_TAIL(dl) == (dln)) { \
TD_DLIST_TAIL(dl) = TD_DLIST_NODE_PREV(dln); \
} \
if (TD_DLIST_NODE_PREV(dln) != NULL) { \
TD_DLIST_NODE_NEXT(TD_DLIST_NODE_PREV(dln)) = TD_DLIST_NODE_NEXT(dln); \
} \
if (TD_DLIST_NODE_NEXT(dln) != NULL) { \
TD_DLIST_NODE_PREV(TD_DLIST_NODE_NEXT(dln)) = TD_DLIST_NODE_PREV(dln); \
} \
TD_DLIST_NELES(dl) -= 1; \
TD_DLIST_NODE_PREV(dln) = TD_DLIST_NODE_NEXT(dln) = NULL; \
} while (0)
// General double linked list
typedef enum { TD_LIST_FORWARD, TD_LIST_BACKWARD } TD_LIST_DIRECTION_T; typedef enum { TD_LIST_FORWARD, TD_LIST_BACKWARD } TD_LIST_DIRECTION_T;
typedef struct _list_node { typedef struct SListNode {
struct _list_node *next; TD_DLIST_NODE(SListNode);
struct _list_node *prev;
char data[]; char data[];
} SListNode; } SListNode;
typedef struct { typedef struct {
struct _list_node *head; TD_DLIST(SListNode);
struct _list_node *tail;
int numOfEles;
int eleSize; int eleSize;
} SList; } SList;
...@@ -39,11 +144,11 @@ typedef struct { ...@@ -39,11 +144,11 @@ typedef struct {
TD_LIST_DIRECTION_T direction; TD_LIST_DIRECTION_T direction;
} SListIter; } SListIter;
#define listHead(l) (l)->head #define listHead(l) TD_DLIST_HEAD(l)
#define listTail(l) (l)->tail #define listTail(l) TD_DLIST_TAIL(l)
#define listNEles(l) (l)->numOfEles #define listNEles(l) TD_DLIST_NELES(l)
#define listEleSize(l) (l)->eleSize #define listEleSize(l) ((l)->eleSize)
#define isListEmpty(l) ((l)->numOfEles == 0) #define isListEmpty(l) (TD_DLIST_NELES(l) == 0)
#define listNodeFree(n) free(n) #define listNodeFree(n) free(n)
void tdListInit(SList *list, int eleSize); void tdListInit(SList *list, int eleSize);
......
...@@ -7,9 +7,8 @@ target_include_directories( ...@@ -7,9 +7,8 @@ target_include_directories(
) )
target_link_libraries( target_link_libraries(
taos taos
PRIVATE common
INTERFACE api INTERFACE api
PRIVATE os util common transport parser catalog function query PRIVATE os util common transport parser catalog function qcom
) )
ADD_SUBDIRECTORY(test) ADD_SUBDIRECTORY(test)
\ No newline at end of file
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
extern "C" { extern "C" {
#endif #endif
#include <common.h>
#include "taos.h" #include "taos.h"
#include "common.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tdef.h" #include "tdef.h"
#include "tep.h" #include "tep.h"
...@@ -76,11 +76,10 @@ typedef struct SAppInfo { ...@@ -76,11 +76,10 @@ typedef struct SAppInfo {
typedef struct STscObj { typedef struct STscObj {
char user[TSDB_USER_LEN]; char user[TSDB_USER_LEN];
char pass[TSDB_PASSWORD_LEN]; char pass[TSDB_PASSWORD_LEN];
char acctId[TSDB_ACCT_ID_LEN];
char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN]; char db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
int32_t acctId;
uint32_t connId; uint32_t connId;
uint64_t id; // ref ID returned by taosAddRef uint64_t id; // ref ID returned by taosAddRef
// struct SSqlObj *sqlList;
void *pTransporter; void *pTransporter;
pthread_mutex_t mutex; // used to protect the operation on db pthread_mutex_t mutex; // used to protect the operation on db
int32_t numOfReqs; // number of sqlObj from this tscObj int32_t numOfReqs; // number of sqlObj from this tscObj
...@@ -88,9 +87,15 @@ typedef struct STscObj { ...@@ -88,9 +87,15 @@ typedef struct STscObj {
} STscObj; } STscObj;
typedef struct SClientResultInfo { typedef struct SClientResultInfo {
SSDataBlock *pData; const char *pMsg;
TAOS_FIELD *resultFields; const char *pData;
TAOS_FIELD *fields;
int32_t numOfCols;
int32_t numOfRows;
int32_t current; int32_t current;
int32_t *length;
TAOS_ROW row;
char **pCol;
} SClientResultInfo; } SClientResultInfo;
typedef struct SReqBody { typedef struct SReqBody {
...@@ -98,6 +103,7 @@ typedef struct SReqBody { ...@@ -98,6 +103,7 @@ typedef struct SReqBody {
void* fp; void* fp;
void* param; void* param;
int32_t paramLen; int32_t paramLen;
int64_t execId; // showId/queryId
SClientResultInfo* pResInfo; SClientResultInfo* pResInfo;
} SRequestBody; } SRequestBody;
...@@ -152,6 +158,7 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, ...@@ -152,6 +158,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); TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen);
void* doFetchRow(SRequestObj* pRequest); void* doFetchRow(SRequestObj* pRequest);
void setResultDataPtr(SClientResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
static int32_t initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSet); static int32_t initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSet);
static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody); static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody);
static void destroyConnectMsg(SRequestMsgBody* pMsgBody); static void destroyRequestMsgBody(SRequestMsgBody* pMsgBody);
static int32_t sendMsgToServer(void *pTransporter, SEpSet* epSet, const SRequestMsgBody *pBody, int64_t* pTransporterId); static int32_t sendMsgToServer(void *pTransporter, SEpSet* epSet, const SRequestMsgBody *pBody, int64_t* pTransporterId);
...@@ -99,17 +99,19 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, ...@@ -99,17 +99,19 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass,
char* key = getClusterKey(user, secretEncrypt, ip, port); char* key = getClusterKey(user, secretEncrypt, ip, port);
SAppInstInfo* pInst = taosHashGet(appInfo.pInstMap, key, strlen(key)); SAppInstInfo** pInst = taosHashGet(appInfo.pInstMap, key, strlen(key));
if (pInst == NULL) { if (pInst == NULL) {
pInst = calloc(1, sizeof(struct SAppInstInfo)); SAppInstInfo* p = calloc(1, sizeof(struct SAppInstInfo));
pInst->mgmtEp = epSet; p->mgmtEp = epSet;
pInst->pTransporter = openTransporter(user, secretEncrypt); p->pTransporter = openTransporter(user, secretEncrypt);
taosHashPut(appInfo.pInstMap, key, strlen(key), &p, POINTER_BYTES);
taosHashPut(appInfo.pInstMap, key, strlen(key), &pInst, POINTER_BYTES); pInst = &p;
} }
return taosConnectImpl(ip, user, &secretEncrypt[0], db, port, NULL, NULL, pInst); tfree(key);
return taosConnectImpl(ip, user, &secretEncrypt[0], db, port, NULL, NULL, *pInst);
} }
TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
...@@ -151,7 +153,7 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { ...@@ -151,7 +153,7 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
void* output = NULL; void* output = NULL;
int32_t outputLen = 0; int32_t outputLen = 0;
code = qParseQuerySql(pRequest->sqlstr, sqlLen, pRequest->requestId, &type, &output, &outputLen, pRequest->msgBuf, ERROR_MSG_BUF_DEFAULT_SIZE); 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) { if (type == TSDB_SQL_CREATE_USER || type == TSDB_SQL_SHOW || type == TSDB_SQL_DROP_USER || type == TSDB_SQL_CREATE_DB) {
pRequest->type = type; pRequest->type = type;
pRequest->body.param = output; pRequest->body.param = output;
pRequest->body.paramLen = outputLen; pRequest->body.paramLen = outputLen;
...@@ -163,7 +165,7 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) { ...@@ -163,7 +165,7 @@ TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen) {
sendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &body, &transporterId); sendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &body, &transporterId);
tsem_wait(&pRequest->body.rspSem); tsem_wait(&pRequest->body.rspSem);
destroyConnectMsg(&body); destroyRequestMsgBody(&body);
} else { } else {
assert(0); assert(0);
} }
...@@ -234,7 +236,7 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con ...@@ -234,7 +236,7 @@ STscObj* taosConnectImpl(const char *ip, const char *user, const char *auth, con
sendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &body, &transporterId); sendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &body, &transporterId);
tsem_wait(&pRequest->body.rspSem); tsem_wait(&pRequest->body.rspSem);
destroyConnectMsg(&body); destroyRequestMsgBody(&body);
if (pRequest->code != TSDB_CODE_SUCCESS) { if (pRequest->code != TSDB_CODE_SUCCESS) {
const char *errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(terrno); const char *errorMsg = (pRequest->code == TSDB_CODE_RPC_FQDN_ERROR) ? taos_errstr(pRequest) : tstrerror(terrno);
...@@ -281,7 +283,7 @@ static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) ...@@ -281,7 +283,7 @@ static int32_t buildConnectMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody)
return 0; return 0;
} }
static void destroyConnectMsg(SRequestMsgBody* pMsgBody) { static void destroyRequestMsgBody(SRequestMsgBody* pMsgBody) {
assert(pMsgBody != NULL); assert(pMsgBody != NULL);
tfree(pMsgBody->pData); tfree(pMsgBody->pData);
} }
...@@ -337,7 +339,14 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { ...@@ -337,7 +339,14 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%"PRId64 " ms", pRequest->requestId, taosMsg[pMsg->msgType], tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%"PRId64 " ms", pRequest->requestId, taosMsg[pMsg->msgType],
tstrerror(pMsg->code), pMsg->contLen, pRequest->metric.rsp - pRequest->metric.start); tstrerror(pMsg->code), pMsg->contLen, pRequest->metric.rsp - pRequest->metric.start);
if (handleRequestRspFp[pRequest->type]) { if (handleRequestRspFp[pRequest->type]) {
pMsg->code = (*handleRequestRspFp[pRequest->type])(pRequest, pMsg->pCont, pMsg->contLen); char *p = malloc(pMsg->contLen);
if (p == NULL) {
pRequest->code = TSDB_CODE_TSC_OUT_OF_MEMORY;
terrno = pRequest->code;
} else {
memcpy(p, pMsg->pCont, pMsg->contLen);
pMsg->code = (*handleRequestRspFp[pRequest->type])(pRequest, p, pMsg->contLen);
}
} }
} else { } else {
tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%"PRId64" ms", pRequest->requestId, taosMsg[pMsg->msgType], tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%"PRId64" ms", pRequest->requestId, taosMsg[pMsg->msgType],
...@@ -381,15 +390,54 @@ void* doFetchRow(SRequestObj* pRequest) { ...@@ -381,15 +390,54 @@ void* doFetchRow(SRequestObj* pRequest) {
assert(pRequest != NULL); assert(pRequest != NULL);
SClientResultInfo* pResultInfo = pRequest->body.pResInfo; SClientResultInfo* pResultInfo = pRequest->body.pResInfo;
if (pResultInfo == NULL || pResultInfo->current >= pResultInfo->pData->info.rows) { if (pResultInfo->pData == NULL || pResultInfo->current >= pResultInfo->numOfRows) {
if (pResultInfo == NULL) { pRequest->type = TSDB_SQL_RETRIEVE_MNODE;
pRequest->body.pResInfo = calloc(1, sizeof(SClientResultInfo));
// pRequest->body.pResInfo. SRequestMsgBody body = {0};
buildRequestMsgFp[pRequest->type](pRequest, &body);
int64_t transporterId = 0;
STscObj* pTscObj = pRequest->pTscObj;
sendMsgToServer(pTscObj->pTransporter, &pTscObj->pAppInfo->mgmtEp.epSet, &body, &transporterId);
tsem_wait(&pRequest->body.rspSem);
destroyRequestMsgBody(&body);
pResultInfo->current = 0;
if (pResultInfo->numOfRows <= pResultInfo->current) {
return NULL;
}
}
for(int32_t i = 0; i < pResultInfo->numOfCols; ++i) {
pResultInfo->row[i] = pResultInfo->pCol[i] + pResultInfo->fields[i].bytes * pResultInfo->current;
if (IS_VAR_DATA_TYPE(pResultInfo->fields[i].type)) {
pResultInfo->length[i] = varDataLen(pResultInfo->row[i]);
pResultInfo->row[i] = varDataVal(pResultInfo->row[i]);
}
}
pResultInfo->current += 1;
return pResultInfo->row;
}
void setResultDataPtr(SClientResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows) {
assert(numOfCols > 0 && pFields != NULL && pResultInfo != NULL);
if (numOfRows == 0) {
return;
} }
// current data set are exhausted, fetch more result from node
// if (pRes->row >= pRes->numOfRows && needToFetchNewBlock(pSql)) { int32_t offset = 0;
// taos_fetch_rows_a(res, waitForRetrieveRsp, pSql->pTscObj); for (int32_t i = 0; i < numOfCols; ++i) {
// tsem_wait(&pSql->rspSem); pResultInfo->length[i] = pResultInfo->fields[i].bytes;
// } pResultInfo->row[i] = (char*) (pResultInfo->pData + offset * pResultInfo->numOfRows);
pResultInfo->pCol[i] = pResultInfo->row[i];
offset += pResultInfo->fields[i].bytes;
} }
} }
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; }
...@@ -28,7 +28,6 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) { ...@@ -28,7 +28,6 @@ int taos_options(TSDB_OPTION option, const void *arg, ...) {
} }
int ret = taos_options_imp(option, (const char*)arg); int ret = taos_options_imp(option, (const char*)arg);
atomic_store_32(&lock, 0); atomic_store_32(&lock, 0);
return ret; return ret;
} }
...@@ -58,7 +57,7 @@ void taos_cleanup(void) { ...@@ -58,7 +57,7 @@ void taos_cleanup(void) {
} }
TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) { TAOS *taos_connect(const char *ip, const char *user, const char *pass, const char *db, uint16_t port) {
int32_t p = (port != 0)? port:tsServerPort; int32_t p = (port != 0) ? port : tsServerPort;
tscDebug("try to connect to %s:%u, user:%s db:%s", ip, p, user, db); tscDebug("try to connect to %s:%u, user:%s db:%s", ip, p, user, db);
if (user == NULL) { if (user == NULL) {
...@@ -110,6 +109,34 @@ void taos_free_result(TAOS_RES *res) { ...@@ -110,6 +109,34 @@ void taos_free_result(TAOS_RES *res) {
destroyRequest(pRequest); destroyRequest(pRequest);
} }
int taos_field_count(TAOS_RES *res) {
if (res == NULL) {
return 0;
}
SRequestObj* pRequest = (SRequestObj*) res;
SClientResultInfo* pResInfo = pRequest->body.pResInfo;
if (pResInfo == NULL) {
return 0;
}
return pResInfo->numOfCols;
}
int taos_num_fields(TAOS_RES *res) {
return taos_field_count(res);
}
TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) {
if (taos_num_fields(res) == 0) {
return NULL;
}
SClientResultInfo* pResInfo = ((SRequestObj*) res)->body.pResInfo;
return pResInfo->fields;
}
TAOS_RES *taos_query(TAOS *taos, const char *sql) { TAOS_RES *taos_query(TAOS *taos, const char *sql) {
if (taos == NULL || sql == NULL) { if (taos == NULL || sql == NULL) {
return NULL; return NULL;
...@@ -131,3 +158,112 @@ TAOS_ROW taos_fetch_row(TAOS_RES *pRes) { ...@@ -131,3 +158,112 @@ TAOS_ROW taos_fetch_row(TAOS_RES *pRes) {
return doFetchRow(pRequest); return doFetchRow(pRequest);
} }
int taos_print_row(char *str, TAOS_ROW row, TAOS_FIELD *fields, int num_fields) {
int32_t len = 0;
for (int i = 0; i < num_fields; ++i) {
if (i > 0) {
str[len++] = ' ';
}
if (row[i] == NULL) {
len += sprintf(str + len, "%s", TSDB_DATA_NULL_STR);
continue;
}
switch (fields[i].type) {
case TSDB_DATA_TYPE_TINYINT:
len += sprintf(str + len, "%d", *((int8_t *)row[i]));
break;
case TSDB_DATA_TYPE_UTINYINT:
len += sprintf(str + len, "%u", *((uint8_t *)row[i]));
break;
case TSDB_DATA_TYPE_SMALLINT:
len += sprintf(str + len, "%d", *((int16_t *)row[i]));
break;
case TSDB_DATA_TYPE_USMALLINT:
len += sprintf(str + len, "%u", *((uint16_t *)row[i]));
break;
case TSDB_DATA_TYPE_INT:
len += sprintf(str + len, "%d", *((int32_t *)row[i]));
break;
case TSDB_DATA_TYPE_UINT:
len += sprintf(str + len, "%u", *((uint32_t *)row[i]));
break;
case TSDB_DATA_TYPE_BIGINT:
len += sprintf(str + len, "%" PRId64, *((int64_t *)row[i]));
break;
case TSDB_DATA_TYPE_UBIGINT:
len += sprintf(str + len, "%" PRIu64, *((uint64_t *)row[i]));
break;
case TSDB_DATA_TYPE_FLOAT: {
float fv = 0;
fv = GET_FLOAT_VAL(row[i]);
len += sprintf(str + len, "%f", fv);
} break;
case TSDB_DATA_TYPE_DOUBLE: {
double dv = 0;
dv = GET_DOUBLE_VAL(row[i]);
len += sprintf(str + len, "%lf", dv);
} break;
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR: {
int32_t charLen = varDataLen((char*)row[i] - VARSTR_HEADER_SIZE);
if (fields[i].type == TSDB_DATA_TYPE_BINARY) {
assert(charLen <= fields[i].bytes && charLen >= 0);
} else {
assert(charLen <= fields[i].bytes * TSDB_NCHAR_SIZE && charLen >= 0);
}
memcpy(str + len, row[i], charLen);
len += charLen;
} break;
case TSDB_DATA_TYPE_TIMESTAMP:
len += sprintf(str + len, "%" PRId64, *((int64_t *)row[i]));
break;
case TSDB_DATA_TYPE_BOOL:
len += sprintf(str + len, "%d", *((int8_t *)row[i]));
default:
break;
}
}
return len;
}
int* taos_fetch_lengths(TAOS_RES *res) {
if (res == NULL) {
return NULL;
}
return ((SRequestObj*) res)->body.pResInfo->length;
}
const char *taos_data_type(int type) {
switch (type) {
case TSDB_DATA_TYPE_NULL: return "TSDB_DATA_TYPE_NULL";
case TSDB_DATA_TYPE_BOOL: return "TSDB_DATA_TYPE_BOOL";
case TSDB_DATA_TYPE_TINYINT: return "TSDB_DATA_TYPE_TINYINT";
case TSDB_DATA_TYPE_SMALLINT: return "TSDB_DATA_TYPE_SMALLINT";
case TSDB_DATA_TYPE_INT: return "TSDB_DATA_TYPE_INT";
case TSDB_DATA_TYPE_BIGINT: return "TSDB_DATA_TYPE_BIGINT";
case TSDB_DATA_TYPE_FLOAT: return "TSDB_DATA_TYPE_FLOAT";
case TSDB_DATA_TYPE_DOUBLE: return "TSDB_DATA_TYPE_DOUBLE";
case TSDB_DATA_TYPE_BINARY: return "TSDB_DATA_TYPE_BINARY";
case TSDB_DATA_TYPE_TIMESTAMP: return "TSDB_DATA_TYPE_TIMESTAMP";
case TSDB_DATA_TYPE_NCHAR: return "TSDB_DATA_TYPE_NCHAR";
default: return "UNKNOWN";
}
}
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
#include <catalog.h> #include <catalog.h>
#include <tname.h>
#include "clientInt.h" #include "clientInt.h"
#include "clientLog.h" #include "clientLog.h"
#include "os.h" #include "os.h"
...@@ -529,7 +530,7 @@ int doBuildAndSendMsg(SSqlObj *pSql) { ...@@ -529,7 +530,7 @@ int doBuildAndSendMsg(SSqlObj *pSql) {
if (pCmd->command == TSDB_SQL_SELECT || if (pCmd->command == TSDB_SQL_SELECT ||
pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_FETCH ||
pCmd->command == TSDB_SQL_RETRIEVE || pCmd->command == TSDB_SQL_RETRIEVE_MNODE ||
pCmd->command == TSDB_SQL_INSERT || pCmd->command == TSDB_SQL_INSERT ||
pCmd->command == TSDB_SQL_CONNECT || pCmd->command == TSDB_SQL_CONNECT ||
pCmd->command == TSDB_SQL_HB || pCmd->command == TSDB_SQL_HB ||
...@@ -2700,7 +2701,7 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) { ...@@ -2700,7 +2701,7 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) {
} }
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
if ((pCmd->command == TSDB_SQL_RETRIEVE) || if ((pCmd->command == TSDB_SQL_RETRIEVE_MNODE) ||
((UTIL_TABLE_IS_CHILD_TABLE(pTableMetaInfo) || UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) && ((UTIL_TABLE_IS_CHILD_TABLE(pTableMetaInfo) || UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) &&
!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_SUBQUERY)) || !TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_SUBQUERY)) ||
(tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) && (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) &&
...@@ -2885,7 +2886,7 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg ...@@ -2885,7 +2886,7 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg
} }
int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool autocreate, bool onlyLocal) { int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool autocreate, bool onlyLocal) {
assert(tIsValidName(&pTableMetaInfo->name)); assert(tNameIsValid(&pTableMetaInfo->name));
char name[TSDB_TABLE_FNAME_LEN] = {0}; char name[TSDB_TABLE_FNAME_LEN] = {0};
tNameExtractFullName(&pTableMetaInfo->name, name); tNameExtractFullName(&pTableMetaInfo->name, name);
...@@ -3138,7 +3139,7 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { ...@@ -3138,7 +3139,7 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
// TODO refactor // TODO refactor
pthread_mutex_lock(&pTscObj->mutex); pthread_mutex_lock(&pTscObj->mutex);
char temp[TSDB_TABLE_FNAME_LEN * 2] = {0}; char temp[TSDB_TABLE_FNAME_LEN * 2] = {0};
int32_t len = sprintf(temp, "%s%s%s", pTscObj->acctId, TS_PATH_DELIMITER, pTscObj->db); int32_t len = sprintf(temp, "%d%s%s", pTscObj->acctId, TS_PATH_DELIMITER, pTscObj->db);
assert(len <= sizeof(pTscObj->db)); assert(len <= sizeof(pTscObj->db));
tstrncpy(pTscObj->db, temp, sizeof(pTscObj->db)); tstrncpy(pTscObj->db, temp, sizeof(pTscObj->db));
...@@ -3153,28 +3154,46 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) { ...@@ -3153,28 +3154,46 @@ int processConnectRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
} }
pTscObj->connId = pConnect->connId; pTscObj->connId = pConnect->connId;
pTscObj->acctId = pConnect->acctId;
// update the appInstInfo // update the appInstInfo
pTscObj->pAppInfo->clusterId = pConnect->clusterId; pTscObj->pAppInfo->clusterId = pConnect->clusterId;
atomic_add_fetch_64(&pTscObj->pAppInfo->numOfConns, 1); atomic_add_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
pRequest->body.pResInfo = calloc(1, sizeof(SClientResultInfo));
pRequest->body.pResInfo->pMsg = pMsg;
tscDebug("0x%" PRIx64 " clusterId:%d, totalConn:%"PRId64, pRequest->requestId, pConnect->clusterId, pTscObj->pAppInfo->numOfConns); tscDebug("0x%" PRIx64 " clusterId:%d, totalConn:%"PRId64, pRequest->requestId, pConnect->clusterId, pTscObj->pAppInfo->numOfConns);
return 0; return 0;
} }
int32_t buildCreateUserMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) { int32_t doBuildMsgSupp(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) {
pMsgBody->msgType = TSDB_MSG_TYPE_CREATE_USER;
pMsgBody->msgLen = sizeof(SCreateUserMsg);
pMsgBody->requestObjRefId = pRequest->self; pMsgBody->requestObjRefId = pRequest->self;
pMsgBody->msgLen = pRequest->body.paramLen;
pMsgBody->pData = pRequest->body.param; pMsgBody->pData = pRequest->body.param;
return 0;
}
int32_t buildShowMsg(SRequestObj* pRequest, SRequestMsgBody* pMsgBody) { switch(pRequest->type) {
case TSDB_SQL_CREATE_USER:
pMsgBody->msgType = TSDB_MSG_TYPE_CREATE_USER;
break;
case TSDB_SQL_CREATE_DB: {
pMsgBody->msgType = TSDB_MSG_TYPE_CREATE_DB;
SCreateDbMsg* pCreateMsg = pRequest->body.param;
SName name = {0};
int32_t ret = tNameSetDbName(&name, pRequest->pTscObj->acctId, pCreateMsg->db, strnlen(pCreateMsg->db, tListLen(pCreateMsg->db)));
if (ret != TSDB_CODE_SUCCESS) {
return -1;
}
tNameGetFullDbName(&name, pCreateMsg->db);
break;
}
case TSDB_SQL_SHOW:
pMsgBody->msgType = TSDB_MSG_TYPE_SHOW; pMsgBody->msgType = TSDB_MSG_TYPE_SHOW;
pMsgBody->msgLen = pRequest->body.paramLen; break;
pMsgBody->requestObjRefId = pRequest->self; }
pMsgBody->pData = pRequest->body.param;
} }
STableMeta* createTableMetaFromMsg(STableMetaMsg* pTableMetaMsg) { STableMeta* createTableMetaFromMsg(STableMetaMsg* pTableMetaMsg) {
...@@ -3217,26 +3236,73 @@ int32_t processShowRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) ...@@ -3217,26 +3236,73 @@ int32_t processShowRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen)
SSchema* pSchema = pMetaMsg->pSchema; SSchema* pSchema = pMetaMsg->pSchema;
pMetaMsg->tuid = htobe64(pMetaMsg->tuid); pMetaMsg->tuid = htobe64(pMetaMsg->tuid);
for (int i = 0; i < pMetaMsg->numOfColumns; ++i) { for (int i = 0; i < pMetaMsg->numOfColumns; ++i) {
pSchema->bytes = htons(pSchema->bytes); pSchema->bytes = htonl(pSchema->bytes);
pSchema++; pSchema++;
} }
STableMeta* pTableMeta = createTableMetaFromMsg(pMetaMsg); pSchema = pMetaMsg->pSchema;
SSchema *pTableSchema = pTableMeta->schema; TAOS_FIELD* pFields = calloc(pMetaMsg->numOfColumns, sizeof(TAOS_FIELD));
for (int32_t i = 0; i < pMetaMsg->numOfColumns; ++i) {
tstrncpy(pFields[i].name, pSchema[i].name, tListLen(pFields[i].name));
pFields[i].type = pSchema[i].type;
pFields[i].bytes = pSchema[i].bytes;
}
TAOS_FIELD* pFields = calloc(1, pTableMeta->tableInfo.numOfColumns); if (pRequest->body.pResInfo == NULL) {
for (int16_t i = 0; i < pTableMeta->tableInfo.numOfColumns; ++i, ++pSchema) { pRequest->body.pResInfo = calloc(1, sizeof(SClientResultInfo));
tstrncpy(pFields[i].name, pTableSchema[i].name, tListLen(pFields[i].name));
pFields[i].type = pTableSchema[i].type;
pFields[i].bytes = pTableSchema[i].bytes;
} }
// pRequest->body.resultFields = pFields; pRequest->body.pResInfo->pMsg = pMsg;
// pRequest->body.numOfFields = pTableMeta->tableInfo.numOfColumns; SClientResultInfo* pResInfo = pRequest->body.pResInfo;
pResInfo->fields = pFields;
pResInfo->numOfCols = pMetaMsg->numOfColumns;
pResInfo->row = calloc(pResInfo->numOfCols, POINTER_BYTES);
pResInfo->pCol = calloc(pResInfo->numOfCols, POINTER_BYTES);
pResInfo->length = calloc(pResInfo->numOfCols, sizeof(int32_t));
pRequest->body.execId = pShow->showId;
return 0; return 0;
} }
int buildRetrieveMnodeMsg(SRequestObj *pRequest, SRequestMsgBody* pMsgBody) {
pMsgBody->msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
pMsgBody->msgLen = sizeof(SRetrieveTableMsg);
pMsgBody->requestObjRefId = pRequest->self;
SRetrieveTableMsg *pRetrieveMsg = calloc(1, sizeof(SRetrieveTableMsg));
pRetrieveMsg->showId = htonl(pRequest->body.execId);
pMsgBody->pData = pRetrieveMsg;
return TSDB_CODE_SUCCESS;
}
int32_t processRetrieveMnodeRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
assert(msgLen >= sizeof(SRetrieveTableRsp));
tfree(pRequest->body.pResInfo->pMsg);
pRequest->body.pResInfo->pMsg = pMsg;
SRetrieveTableRsp *pRetrieve = (SRetrieveTableRsp *) pMsg;
pRetrieve->numOfRows = htonl(pRetrieve->numOfRows);
pRetrieve->precision = htons(pRetrieve->precision);
SClientResultInfo* pResInfo = pRequest->body.pResInfo;
pResInfo->numOfRows = pRetrieve->numOfRows;
pResInfo->pData = pRetrieve->data; // todo fix this in async model
pResInfo->current = 0;
setResultDataPtr(pResInfo, pResInfo->fields, pResInfo->numOfCols, pResInfo->numOfRows);
tscDebug("0x%"PRIx64" numOfRows:%d, complete:%d, qId:0x%"PRIx64, pRequest->self, pRetrieve->numOfRows,
pRetrieve->completed, pRequest->body.execId);
return 0;
}
int32_t processCreateDbRsp(SRequestObj *pRequest, const char* pMsg, int32_t msgLen) {
// todo rsp with the vnode id list
}
void initMsgHandleFp() { void initMsgHandleFp() {
#if 0 #if 0
tscBuildMsg[TSDB_SQL_SELECT] = tscBuildQueryMsg; tscBuildMsg[TSDB_SQL_SELECT] = tscBuildQueryMsg;
...@@ -3273,7 +3339,7 @@ void initMsgHandleFp() { ...@@ -3273,7 +3339,7 @@ void initMsgHandleFp() {
tscBuildMsg[TSDB_SQL_HB] = tscBuildHeartBeatMsg; tscBuildMsg[TSDB_SQL_HB] = tscBuildHeartBeatMsg;
tscBuildMsg[TSDB_SQL_SHOW] = tscBuildShowMsg; tscBuildMsg[TSDB_SQL_SHOW] = tscBuildShowMsg;
tscBuildMsg[TSDB_SQL_RETRIEVE] = tscBuildRetrieveFromMgmtMsg; tscBuildMsg[TSDB_SQL_RETRIEVE_MNODE] = tscBuildRetrieveFromMgmtMsg;
tscBuildMsg[TSDB_SQL_KILL_QUERY] = tscBuildKillMsg; tscBuildMsg[TSDB_SQL_KILL_QUERY] = tscBuildKillMsg;
tscBuildMsg[TSDB_SQL_KILL_STREAM] = tscBuildKillMsg; tscBuildMsg[TSDB_SQL_KILL_STREAM] = tscBuildKillMsg;
tscBuildMsg[TSDB_SQL_KILL_CONNECTION] = tscBuildKillMsg; tscBuildMsg[TSDB_SQL_KILL_CONNECTION] = tscBuildKillMsg;
...@@ -3291,7 +3357,7 @@ void initMsgHandleFp() { ...@@ -3291,7 +3357,7 @@ void initMsgHandleFp() {
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_FUNC] = tscProcessRetrieveFuncRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE_FUNC] = tscProcessRetrieveFuncRsp;
tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp; tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp;
tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromNode; // rsp handled by same function. tscProcessMsgRsp[TSDB_SQL_RETRIEVE_MNODE] = tscProcessRetrieveRspFromNode; // rsp handled by same function.
tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp; tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp;
tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessLocalRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessLocalRetrieveRsp;
...@@ -3316,9 +3382,14 @@ void initMsgHandleFp() { ...@@ -3316,9 +3382,14 @@ void initMsgHandleFp() {
buildRequestMsgFp[TSDB_SQL_CONNECT] = buildConnectMsg; buildRequestMsgFp[TSDB_SQL_CONNECT] = buildConnectMsg;
handleRequestRspFp[TSDB_SQL_CONNECT] = processConnectRsp; handleRequestRspFp[TSDB_SQL_CONNECT] = processConnectRsp;
buildRequestMsgFp[TSDB_SQL_CREATE_USER] = buildCreateUserMsg; buildRequestMsgFp[TSDB_SQL_CREATE_USER] = doBuildMsgSupp;
buildRequestMsgFp[TSDB_SQL_SHOW] = buildShowMsg; buildRequestMsgFp[TSDB_SQL_SHOW] = doBuildMsgSupp;
handleRequestRspFp[TSDB_SQL_SHOW] = processShowRsp; handleRequestRspFp[TSDB_SQL_SHOW] = processShowRsp;
buildRequestMsgFp[TSDB_SQL_RETRIEVE_MNODE] = buildRetrieveMnodeMsg;
handleRequestRspFp[TSDB_SQL_RETRIEVE_MNODE]= processRetrieveMnodeRsp;
buildRequestMsgFp[TSDB_SQL_CREATE_DB] = doBuildMsgSupp;
handleRequestRspFp[TSDB_SQL_CREATE_DB] = processCreateDbRsp;
} }
\ No newline at end of file
...@@ -127,8 +127,6 @@ void destroyTscObj(void *pObj) { ...@@ -127,8 +127,6 @@ void destroyTscObj(void *pObj) {
atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1); atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
tscDebug("connObj 0x%"PRIx64" destroyed, totalConn:%"PRId64, pTscObj->id, pTscObj->pAppInfo->numOfConns); tscDebug("connObj 0x%"PRIx64" destroyed, totalConn:%"PRId64, pTscObj->id, pTscObj->pAppInfo->numOfConns);
closeTransporter(pTscObj);
pthread_mutex_destroy(&pTscObj->mutex); pthread_mutex_destroy(&pTscObj->mutex);
tfree(pTscObj); tfree(pTscObj);
} }
...@@ -190,6 +188,12 @@ static void doDestroyRequest(void* p) { ...@@ -190,6 +188,12 @@ static void doDestroyRequest(void* p) {
tfree(pRequest->sqlstr); tfree(pRequest->sqlstr);
tfree(pRequest->pInfo); tfree(pRequest->pInfo);
if (pRequest->body.pResInfo != NULL) {
tfree(pRequest->body.pResInfo->pData);
tfree(pRequest->body.pResInfo->pMsg);
tfree(pRequest->body.pResInfo);
}
deregisterRequest(pRequest); deregisterRequest(pRequest);
tfree(pRequest); tfree(pRequest);
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-compare"
#include "../inc/clientInt.h"
#include "taos.h" #include "taos.h"
namespace { namespace {
...@@ -34,19 +35,90 @@ int main(int argc, char** argv) { ...@@ -34,19 +35,90 @@ int main(int argc, char** argv) {
} }
TEST(testCase, driverInit_Test) { TEST(testCase, driverInit_Test) {
taos_init();
}
TEST(testCase, connect_Test) {
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0); 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);
TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'");
if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
printf("failed to create user, reason:%s\n", taos_errstr(pRes));
}
taos_free_result(pRes);
taos_close(pConn);
}
// TAOS_RES* pRes = taos_query(pConn, "create user abc pass 'abc'"); //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) { // if (taos_errno(pRes) != TSDB_CODE_SUCCESS) {
// printf("failed to create user, reason:%s\n", taos_errstr(pRes)); // printf("failed to create user, reason:%s\n", taos_errstr(pRes));
// } // }
// //
// taos_free_result(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);
TAOS_RES* pRes = taos_query(pConn, "show users"); TAOS_RES* pRes = taos_query(pConn, "show users");
TAOS_ROW pRow = taos_fetch_row(pRes); TAOS_ROW pRow = NULL;
assert(pRow != NULL);
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
int32_t numOfFields = taos_num_fields(pRes);
char str[512] = {0};
while((pRow = taos_fetch_row(pRes)) != NULL) {
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
printf("%s\n", str);
}
taos_close(pConn);
}
TEST(testCase, 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;
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
int32_t numOfFields = taos_num_fields(pRes);
char str[512] = {0};
while((pRow = taos_fetch_row(pRes)) != NULL) {
int32_t code = taos_print_row(str, pRow, pFields, numOfFields);
printf("%s\n", str);
}
taos_close(pConn);
}
TEST(testCase, create_db_Test) {
TAOS* pConn = taos_connect("ubuntu", "root", "taosdata", NULL, 0);
assert(pConn != NULL);
TAOS_RES* pRes = taos_query(pConn, "create database abc");
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
ASSERT_TRUE(pFields == NULL);
int32_t numOfFields = taos_num_fields(pRes);
ASSERT_EQ(numOfFields, 0);
taos_close(pConn); taos_close(pConn);
} }
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
#include "tname.h" #include "tname.h"
#include "taosmsg.h" #include "taosmsg.h"
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
#define VALIDNUMOFTAGS(x) ((x) >= 0 && (x) <= TSDB_MAX_TAGS)
#define VALID_NAME_TYPE(x) ((x) == TSDB_DB_NAME_T || (x) == TSDB_TABLE_NAME_T) #define VALID_NAME_TYPE(x) ((x) == TSDB_DB_NAME_T || (x) == TSDB_TABLE_NAME_T)
char* extractDBName(const char* tableId, char* name) { char* extractDBName(const char* tableId, char* name) {
...@@ -120,84 +117,11 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in ...@@ -120,84 +117,11 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in
#endif #endif
static struct SSchema _s = {
.colId = TSDB_TBNAME_COLUMN_INDEX,
.type = TSDB_DATA_TYPE_BINARY,
.bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE,
.name = "tbname",
};
SSchema* tGetTbnameColumnSchema() {
return &_s;
}
static bool doValidateSchema(SSchema* pSchema, int32_t numOfCols, int32_t maxLen) {
int32_t rowLen = 0;
for (int32_t i = 0; i < numOfCols; ++i) {
// 1. valid types
if (!isValidDataType(pSchema[i].type)) {
return false;
}
// 2. valid length for each type
if (pSchema[i].type == TSDB_DATA_TYPE_BINARY) {
if (pSchema[i].bytes > TSDB_MAX_BINARY_LEN) {
return false;
}
} else if (pSchema[i].type == TSDB_DATA_TYPE_NCHAR) {
if (pSchema[i].bytes > TSDB_MAX_NCHAR_LEN) {
return false;
}
} else {
if (pSchema[i].bytes != tDataTypes[pSchema[i].type].bytes) {
return false;
}
}
// 3. valid column names
for (int32_t j = i + 1; j < numOfCols; ++j) {
if (strncasecmp(pSchema[i].name, pSchema[j].name, sizeof(pSchema[i].name) - 1) == 0) {
return false;
}
}
rowLen += pSchema[i].bytes;
}
return rowLen <= maxLen;
}
bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags) {
if (!VALIDNUMOFCOLS(numOfCols)) {
return false;
}
if (!VALIDNUMOFTAGS(numOfTags)) {
return false;
}
/* first column must be the timestamp, which is a primary key */
if (pSchema[0].type != TSDB_DATA_TYPE_TIMESTAMP) {
return false;
}
if (!doValidateSchema(pSchema, numOfCols, TSDB_MAX_BYTES_PER_ROW)) {
return false;
}
if (!doValidateSchema(&pSchema[numOfCols], numOfTags, TSDB_MAX_TAGS_LEN)) {
return false;
}
return true;
}
int32_t tNameExtractFullName(const SName* name, char* dst) { int32_t tNameExtractFullName(const SName* name, char* dst) {
assert(name != NULL && dst != NULL); assert(name != NULL && dst != NULL);
// invalid full name format, abort // invalid full name format, abort
if (!tIsValidName(name)) { if (!tNameIsValid(name)) {
return -1; return -1;
} }
...@@ -230,7 +154,7 @@ int32_t tNameLen(const SName* name) { ...@@ -230,7 +154,7 @@ int32_t tNameLen(const SName* name) {
} }
} }
bool tIsValidName(const SName* name) { bool tNameIsValid(const SName* name) {
assert(name != NULL); assert(name != NULL);
if (!VALID_NAME_TYPE(name->type)) { if (!VALID_NAME_TYPE(name->type)) {
...@@ -265,13 +189,13 @@ int32_t tNameGetDbName(const SName* name, char* dst) { ...@@ -265,13 +189,13 @@ int32_t tNameGetDbName(const SName* name, char* dst) {
int32_t tNameGetFullDbName(const SName* name, char* dst) { int32_t tNameGetFullDbName(const SName* name, char* dst) {
assert(name != NULL && dst != NULL); assert(name != NULL && dst != NULL);
snprintf(dst, TSDB_ACCT_ID_LEN + TS_PATH_DELIMITER_LEN + TSDB_DB_NAME_LEN, // there is a over write risk snprintf(dst, TSDB_ACCT_ID_LEN + TS_PATH_DELIMITER_LEN + TSDB_DB_NAME_LEN, // there is a over write risk
"%s.%s", name->acctId, name->dbname); "%d.%s", name->acctId, name->dbname);
return 0; return 0;
} }
bool tNameIsEmpty(const SName* name) { bool tNameIsEmpty(const SName* name) {
assert(name != NULL); assert(name != NULL);
return name->type == 0 || strlen(name->acctId) <= 0; return name->type == 0 || name->acctId == 0;
} }
const char* tNameGetTableName(const SName* name) { const char* tNameGetTableName(const SName* name) {
...@@ -283,32 +207,23 @@ void tNameAssign(SName* dst, const SName* src) { ...@@ -283,32 +207,23 @@ void tNameAssign(SName* dst, const SName* src) {
memcpy(dst, src, sizeof(SName)); memcpy(dst, src, sizeof(SName));
} }
//int32_t tNameSetDbName(SName* dst, const char* acct, SStrToken* dbToken) { int32_t tNameSetDbName(SName* dst, int32_t acct, const char* dbName, size_t nameLen) {
// assert(dst != NULL && dbToken != NULL && acct != NULL); assert(dst != NULL && dbName != NULL && nameLen > 0);
//
// // too long account id or too long db name
// if (strlen(acct) >= tListLen(dst->acctId) || dbToken->n >= tListLen(dst->dbname)) {
// return -1;
// }
//
// dst->type = TSDB_DB_NAME_T;
// tstrncpy(dst->acctId, acct, tListLen(dst->acctId));
// tstrncpy(dst->dbname, dbToken->z, dbToken->n + 1);
// return 0;
//}
int32_t tNameSetAcctId(SName* dst, const char* acct) {
assert(dst != NULL && acct != NULL);
// too long account id or too long db name // too long account id or too long db name
if (strlen(acct) >= tListLen(dst->acctId)) { if (nameLen >= tListLen(dst->dbname)) {
return -1; return -1;
} }
tstrncpy(dst->acctId, acct, tListLen(dst->acctId)); dst->type = TSDB_DB_NAME_T;
dst->acctId = acct;
assert(strlen(dst->acctId) > 0); tstrncpy(dst->dbname, dbName, nameLen + 1);
return 0;
}
int32_t tNameSetAcctId(SName* dst, int32_t acctId) {
assert(dst != NULL && acct != NULL);
dst->acctId = acctId;
return 0; return 0;
} }
...@@ -325,14 +240,11 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) { ...@@ -325,14 +240,11 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
int32_t len = (int32_t)(p - str); int32_t len = (int32_t)(p - str);
// too long account id or too long db name // too long account id or too long db name
if ((len >= tListLen(dst->acctId)) || (len <= 0)) { // if ((len >= tListLen(dst->acctId)) || (len <= 0)) {
return -1; // return -1;
} // }
// memcpy (dst->acctId, str, len);
memcpy (dst->acctId, str, len); dst->acctId = strtoll(str, NULL, 10);
dst->acctId[len] = 0;
assert(strlen(dst->acctId) > 0);
} }
if ((type & T_NAME_DB) == T_NAME_DB) { if ((type & T_NAME_DB) == T_NAME_DB) {
......
...@@ -92,6 +92,7 @@ void dmnPrintVersion() { ...@@ -92,6 +92,7 @@ void dmnPrintVersion() {
} }
int dmnReadConfig(const char *path) { int dmnReadConfig(const char *path) {
tstrncpy(configDir, global.configDir, PATH_MAX);
taosInitGlobalCfg(); taosInitGlobalCfg();
taosReadGlobalLogCfg(); taosReadGlobalLogCfg();
......
...@@ -38,14 +38,13 @@ static void dndInitMsgFp(STransMgmt *pMgmt) { ...@@ -38,14 +38,13 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_TABLE] = dndProcessVnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_DROP_TABLE] = dndProcessVnodeWriteMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_TABLE] = dndProcessVnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_TABLE] = dndProcessVnodeWriteMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = dndProcessVnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_UPDATE_TAG_VAL] = dndProcessVnodeWriteMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_TABLE_META] = dndProcessVnodeQueryMsg; pMgmt->msgFp[TSDB_MSG_TYPE_TABLE_META] = dndProcessMnodeReadMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_TABLES_META] = dndProcessVnodeQueryMsg; pMgmt->msgFp[TSDB_MSG_TYPE_TABLES_META] = dndProcessVnodeQueryMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_MQ_QUERY] = dndProcessVnodeQueryMsg; pMgmt->msgFp[TSDB_MSG_TYPE_MQ_QUERY] = dndProcessVnodeQueryMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = dndProcessVnodeQueryMsg; pMgmt->msgFp[TSDB_MSG_TYPE_MQ_CONSUME] = dndProcessVnodeQueryMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_MQ_CONNECT] = dndProcessVnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_MQ_CONNECT] = dndProcessVnodeWriteMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = dndProcessVnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_MQ_DISCONNECT] = dndProcessVnodeWriteMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_MQ_ACK] = dndProcessVnodeWriteMsg; pMgmt->msgFp[TSDB_MSG_TYPE_MQ_SET] = dndProcessVnodeWriteMsg;
pMgmt->msgFp[TSDB_MSG_TYPE_MQ_RESET] = dndProcessVnodeWriteMsg;
// msg from client to mnode // msg from client to mnode
pMgmt->msgFp[TSDB_MSG_TYPE_CONNECT] = dndProcessMnodeReadMsg; pMgmt->msgFp[TSDB_MSG_TYPE_CONNECT] = dndProcessMnodeReadMsg;
......
enable_testing()
add_subdirectory(acct) add_subdirectory(acct)
# add_subdirectory(auth) # add_subdirectory(auth)
# add_subdirectory(balance) # add_subdirectory(balance)
# add_subdirectory(cluster) add_subdirectory(cluster)
add_subdirectory(db) add_subdirectory(db)
add_subdirectory(dnode) add_subdirectory(dnode)
# add_subdirectory(func) # add_subdirectory(func)
# add_subdirectory(mnode) # add_subdirectory(mnode)
# add_subdirectory(profile) # add_subdirectory(profile)
# add_subdirectory(show) # add_subdirectory(show)
# add_subdirectory(stb) add_subdirectory(stb)
# add_subdirectory(sync) # add_subdirectory(sync)
# add_subdirectory(telem) # add_subdirectory(telem)
# add_subdirectory(trans) # add_subdirectory(trans)
......
...@@ -21,8 +21,6 @@ target_include_directories(dnode_test_acct ...@@ -21,8 +21,6 @@ target_include_directories(dnode_test_acct
"${CMAKE_CURRENT_SOURCE_DIR}/../sut" "${CMAKE_CURRENT_SOURCE_DIR}/../sut"
) )
enable_testing()
add_test( add_test(
NAME dnode_test_acct NAME dnode_test_acct
COMMAND dnode_test_acct COMMAND dnode_test_acct
......
/** /**
* @file vnodeApiTests.cpp * @file acct.cpp
* @author slguan (slguan@taosdata.com) * @author slguan (slguan@taosdata.com)
* @brief DNODE module acct-msg tests * @brief DNODE module acct-msg tests
* @version 0.1 * @version 0.1
......
add_executable(dndTestCluster "") add_executable(dnode_test_cluster "")
target_sources(dndTestCluster target_sources(dnode_test_cluster
PRIVATE PRIVATE
"cluster.cpp" "cluster.cpp"
"../sut/deploy.cpp" "../sut/deploy.cpp"
) )
target_link_libraries( target_link_libraries(
dndTestCluster dnode_test_cluster
PUBLIC dnode PUBLIC dnode
PUBLIC util PUBLIC util
PUBLIC os PUBLIC os
PUBLIC gtest_main PUBLIC gtest_main
) )
target_include_directories(dndTestCluster target_include_directories(dnode_test_cluster
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt" "${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
"${CMAKE_CURRENT_SOURCE_DIR}/../sut" "${CMAKE_CURRENT_SOURCE_DIR}/../sut"
) )
enable_testing()
add_test( add_test(
NAME dndTestCluster NAME dnode_test_cluster
COMMAND dndTestCluster COMMAND dnode_test_cluster
) )
/** /**
* @file vnodeApiTests.cpp * @file cluster.cpp
* @author slguan (slguan@taosdata.com) * @author slguan (slguan@taosdata.com)
* @brief DNODE module cluster-msg tests * @brief DNODE module cluster-msg tests
* @version 0.1 * @version 0.1
...@@ -13,154 +13,158 @@ ...@@ -13,154 +13,158 @@
class DndTestCluster : public ::testing::Test { class DndTestCluster : public ::testing::Test {
protected: protected:
void SetUp() override {} static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
void TearDown() override {} SServer* pServer = createServer(path, fqdn, port, firstEp);
ASSERT(pServer);
return pServer;
}
static void SetUpTestSuite() { static void SetUpTestSuite() {
const char* user = "root"; initLog("/tmp/tdlog");
const char* pass = "taosdata";
const char* path = "/tmp/dndTestCluster";
const char* fqdn = "localhost";
uint16_t port = 9521;
pServer = createServer(path, fqdn, port); const char* fqdn = "localhost";
ASSERT(pServer); const char* firstEp = "localhost:9030";
pClient = createClient(user, pass, fqdn, port); pServer = CreateServer("/tmp/dnode_test_cluster", fqdn, 9030, firstEp);
pClient = createClient("root", "taosdata", fqdn, 9030);
taosMsleep(1100);
} }
static void TearDownTestSuite() { static void TearDownTestSuite() {
stopServer(pServer); stopServer(pServer);
dropClient(pClient); dropClient(pClient);
pServer = NULL;
pClient = NULL;
} }
static SServer* pServer; static SServer* pServer;
static SClient* pClient; static SClient* pClient;
static int32_t connId; static int32_t connId;
};
SServer* DndTestCluster::pServer; public:
SClient* DndTestCluster::pClient; void SetUp() override {}
int32_t DndTestCluster::connId; void TearDown() override {}
TEST_F(DndTestCluster, ShowCluster) { void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns, const char* db) {
ASSERT_NE(pClient, nullptr); SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
int32_t showId = 0; pShow->type = showType;
if (db != NULL) {
{ strcpy(pShow->db, db);
SShowMsg* pReq = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg)); }
pReq->type = TSDB_MGMT_TABLE_CLUSTER; SRpcMsg showRpcMsg = {0};
strcpy(pReq->db, ""); showRpcMsg.pCont = pShow;
showRpcMsg.contLen = sizeof(SShowMsg);
SRpcMsg rpcMsg = {0}; showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
rpcMsg.pCont = pReq;
rpcMsg.contLen = sizeof(SShowMsg); sendMsg(pClient, &showRpcMsg);
rpcMsg.msgType = TSDB_MSG_TYPE_SHOW; ASSERT_NE(pClient->pRsp, nullptr);
ASSERT_EQ(pClient->pRsp->code, 0);
sendMsg(pClient, &rpcMsg); ASSERT_NE(pClient->pRsp->pCont, nullptr);
SRpcMsg* pMsg = pClient->pRsp;
ASSERT_NE(pMsg, nullptr); SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
ASSERT_NE(pShowRsp, nullptr);
SShowRsp* pRsp = (SShowRsp*)pMsg->pCont; pShowRsp->showId = htonl(pShowRsp->showId);
ASSERT_NE(pRsp, nullptr); pMeta = &pShowRsp->tableMeta;
pRsp->showId = htonl(pRsp->showId); pMeta->numOfTags = htonl(pMeta->numOfTags);
STableMetaMsg* pMeta = &pRsp->tableMeta; pMeta->numOfColumns = htonl(pMeta->numOfColumns);
pMeta->contLen = htonl(pMeta->contLen); pMeta->sversion = htonl(pMeta->sversion);
pMeta->numOfColumns = htons(pMeta->numOfColumns); pMeta->tversion = htonl(pMeta->tversion);
pMeta->sversion = htons(pMeta->sversion); pMeta->tuid = htobe64(pMeta->tuid);
pMeta->tversion = htons(pMeta->tversion);
pMeta->tid = htonl(pMeta->tid);
pMeta->uid = htobe64(pMeta->uid);
pMeta->suid = htobe64(pMeta->suid); pMeta->suid = htobe64(pMeta->suid);
showId = pRsp->showId; showId = pShowRsp->showId;
EXPECT_NE(pRsp->showId, 0); EXPECT_NE(pShowRsp->showId, 0);
EXPECT_EQ(pMeta->contLen, 0); EXPECT_STREQ(pMeta->tbFname, showName);
EXPECT_STREQ(pMeta->tbFname, "show cluster");
EXPECT_EQ(pMeta->numOfTags, 0); EXPECT_EQ(pMeta->numOfTags, 0);
EXPECT_EQ(pMeta->numOfColumns, columns);
EXPECT_EQ(pMeta->precision, 0); EXPECT_EQ(pMeta->precision, 0);
EXPECT_EQ(pMeta->tableType, 0); EXPECT_EQ(pMeta->tableType, 0);
EXPECT_EQ(pMeta->numOfColumns, 3); EXPECT_EQ(pMeta->update, 0);
EXPECT_EQ(pMeta->sversion, 0); EXPECT_EQ(pMeta->sversion, 0);
EXPECT_EQ(pMeta->tversion, 0); EXPECT_EQ(pMeta->tversion, 0);
EXPECT_EQ(pMeta->tid, 0); EXPECT_EQ(pMeta->tuid, 0);
EXPECT_EQ(pMeta->uid, 0);
EXPECT_STREQ(pMeta->sTableName, "");
EXPECT_EQ(pMeta->suid, 0); EXPECT_EQ(pMeta->suid, 0);
}
SSchema* pSchema = NULL; void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
pSchema = &pMeta->pSchema[0]; SSchema* pSchema = &pMeta->pSchema[index];
pSchema->bytes = htons(pSchema->bytes); 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, "id");
pSchema = &pMeta->pSchema[1];
pSchema->bytes = htons(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0); EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY); EXPECT_EQ(pSchema->type, type);
EXPECT_EQ(pSchema->bytes, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE); EXPECT_EQ(pSchema->bytes, bytes);
EXPECT_STREQ(pSchema->name, "name"); EXPECT_STREQ(pSchema->name, name);
}
pSchema = &pMeta->pSchema[2]; void SendThenCheckShowRetrieveMsg(int32_t rows) {
pSchema->bytes = htons(pSchema->bytes); SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
EXPECT_EQ(pSchema->colId, 0); pRetrieve->showId = htonl(showId);
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP); pRetrieve->free = 0;
EXPECT_EQ(pSchema->bytes, 8);
EXPECT_STREQ(pSchema->name, "create_time"); 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() {
SRetrieveTableMsg* pReq = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg)); int32_t data = *((int32_t*)(pData + pos));
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);
char* pData = pRsp->data;
int32_t pos = 0;
int32_t id = *((int32_t*)(pData + pos));
pos += sizeof(int32_t); pos += sizeof(int32_t);
EXPECT_GT(data, 0);
}
int32_t nameLen = varDataLen(pData + pos); 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); pos += sizeof(VarDataLenT);
char* data = (char*)(pData + pos);
pos += len;
}
char* name = (char*)(pData + pos); int32_t showId;
pos += TSDB_CLUSTER_ID_LEN; STableMetaMsg* pMeta;
SRetrieveTableRsp* pRetrieveRsp;
char* pData;
int32_t pos;
};
int64_t create_time = *((int64_t*)(pData + pos)); SServer* DndTestCluster::pServer;
pos += sizeof(int64_t); SClient* DndTestCluster::pClient;
int32_t DndTestCluster::connId;
EXPECT_NE(id, 0); TEST_F(DndTestCluster, 01_ShowCluster) {
EXPECT_EQ(nameLen, 36); SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_CLUSTER, "show cluster", 3, NULL);
EXPECT_STRNE(name, ""); CheckSchema(0, TSDB_DATA_TYPE_INT, 4, "id");
EXPECT_GT(create_time, 0); CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE, "name");
printf("--- id:%d nameLen:%d name:%s time:%" PRId64 " --- \n", id, nameLen, name, create_time); CheckSchema(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
}
SendThenCheckShowRetrieveMsg(1);
CheckInt32();
CheckBinary(TSDB_CLUSTER_ID_LEN);
CheckTimestamp();
} }
\ No newline at end of file
...@@ -21,8 +21,6 @@ target_include_directories(dnode_test_db ...@@ -21,8 +21,6 @@ target_include_directories(dnode_test_db
"${CMAKE_CURRENT_SOURCE_DIR}/../sut" "${CMAKE_CURRENT_SOURCE_DIR}/../sut"
) )
enable_testing()
add_test( add_test(
NAME dnode_test_db NAME dnode_test_db
COMMAND dnode_test_db COMMAND dnode_test_db
......
/** /**
* @file vnodeApiTests.cpp * @file db.cpp
* @author slguan (slguan@taosdata.com) * @author slguan (slguan@taosdata.com)
* @brief DNODE module db-msg tests * @brief DNODE module db-msg tests
* @version 0.1 * @version 0.1
...@@ -88,7 +88,7 @@ class DndTestDb : public ::testing::Test { ...@@ -88,7 +88,7 @@ class DndTestDb : public ::testing::Test {
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) { void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
SSchema* pSchema = &pMeta->pSchema[index]; SSchema* pSchema = &pMeta->pSchema[index];
pSchema->bytes = htons(pSchema->bytes); pSchema->bytes = htonl(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0); EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, type); EXPECT_EQ(pSchema->type, type);
EXPECT_EQ(pSchema->bytes, bytes); EXPECT_EQ(pSchema->bytes, bytes);
...@@ -114,17 +114,14 @@ class DndTestDb : public ::testing::Test { ...@@ -114,17 +114,14 @@ class DndTestDb : public ::testing::Test {
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont; pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
ASSERT_NE(pRetrieveRsp, nullptr); ASSERT_NE(pRetrieveRsp, nullptr);
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
pRetrieveRsp->offset = htobe64(pRetrieveRsp->offset);
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen); pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
EXPECT_EQ(pRetrieveRsp->numOfRows, rows); EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
EXPECT_EQ(pRetrieveRsp->offset, 0);
EXPECT_EQ(pRetrieveRsp->useconds, 0); EXPECT_EQ(pRetrieveRsp->useconds, 0);
// EXPECT_EQ(pRetrieveRsp->completed, completed); // EXPECT_EQ(pRetrieveRsp->completed, completed);
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI); EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
EXPECT_EQ(pRetrieveRsp->compressed, 0); EXPECT_EQ(pRetrieveRsp->compressed, 0);
EXPECT_EQ(pRetrieveRsp->reserved, 0);
EXPECT_EQ(pRetrieveRsp->compLen, 0); EXPECT_EQ(pRetrieveRsp->compLen, 0);
pData = pRetrieveRsp->data; pData = pRetrieveRsp->data;
...@@ -182,13 +179,13 @@ int32_t DndTestDb::connId; ...@@ -182,13 +179,13 @@ int32_t DndTestDb::connId;
TEST_F(DndTestDb, 01_ShowDb) { TEST_F(DndTestDb, 01_ShowDb) {
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DB, "show databases", 17, NULL); 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(0, TSDB_DATA_TYPE_BINARY, TSDB_DB_NAME_LEN - 1 + VARSTR_HEADER_SIZE, "name");
CheckSchema(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create time"); CheckSchema(1, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "vgroups"); CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "vgroups");
CheckSchema(3, TSDB_DATA_TYPE_SMALLINT, 2, "replica"); CheckSchema(3, TSDB_DATA_TYPE_SMALLINT, 2, "replica");
CheckSchema(4, TSDB_DATA_TYPE_SMALLINT, 2, "quorum"); CheckSchema(4, TSDB_DATA_TYPE_SMALLINT, 2, "quorum");
CheckSchema(5, TSDB_DATA_TYPE_SMALLINT, 2, "days"); CheckSchema(5, TSDB_DATA_TYPE_SMALLINT, 2, "days");
CheckSchema(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "keep0,keep1,keep2"); CheckSchema(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "keep0,keep1,keep2");
CheckSchema(7, TSDB_DATA_TYPE_INT, 4, "cache(MB)"); CheckSchema(7, TSDB_DATA_TYPE_INT, 4, "cache");
CheckSchema(8, TSDB_DATA_TYPE_INT, 4, "blocks"); CheckSchema(8, TSDB_DATA_TYPE_INT, 4, "blocks");
CheckSchema(9, TSDB_DATA_TYPE_INT, 4, "minrows"); CheckSchema(9, TSDB_DATA_TYPE_INT, 4, "minrows");
CheckSchema(10, TSDB_DATA_TYPE_INT, 4, "maxrows"); CheckSchema(10, TSDB_DATA_TYPE_INT, 4, "maxrows");
......
...@@ -21,8 +21,6 @@ target_include_directories(dnode_test_dnode ...@@ -21,8 +21,6 @@ target_include_directories(dnode_test_dnode
"${CMAKE_CURRENT_SOURCE_DIR}/../sut" "${CMAKE_CURRENT_SOURCE_DIR}/../sut"
) )
enable_testing()
add_test( add_test(
NAME dnode_test_dnode NAME dnode_test_dnode
COMMAND dnode_test_dnode COMMAND dnode_test_dnode
......
/** /**
* @file vnodeApiTests.cpp * @file dnode.cpp
* @author slguan (slguan@taosdata.com) * @author slguan (slguan@taosdata.com)
* @brief DNODE module dnode-msg tests * @brief DNODE module dnode-msg tests
* @version 0.1 * @version 0.1
...@@ -81,8 +81,8 @@ class DndTestDnode : public ::testing::Test { ...@@ -81,8 +81,8 @@ class DndTestDnode : public ::testing::Test {
pMeta->numOfTags = htonl(pMeta->numOfTags); pMeta->numOfTags = htonl(pMeta->numOfTags);
pMeta->numOfColumns = htonl(pMeta->numOfColumns); pMeta->numOfColumns = htonl(pMeta->numOfColumns);
pMeta->sversion = htonl(pMeta->sversion); pMeta->sversion = htonl(pMeta->sversion);
pMeta->tversion = htons(pMeta->tversion); pMeta->tversion = htonl(pMeta->tversion);
pMeta->tuid = htonl(pMeta->tuid); pMeta->tuid = htobe64(pMeta->tuid);
pMeta->suid = htobe64(pMeta->suid); pMeta->suid = htobe64(pMeta->suid);
showId = pShowRsp->showId; showId = pShowRsp->showId;
...@@ -102,7 +102,7 @@ class DndTestDnode : public ::testing::Test { ...@@ -102,7 +102,7 @@ class DndTestDnode : public ::testing::Test {
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) { void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
SSchema* pSchema = &pMeta->pSchema[index]; SSchema* pSchema = &pMeta->pSchema[index];
pSchema->bytes = htons(pSchema->bytes); pSchema->bytes = htonl(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0); EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, type); EXPECT_EQ(pSchema->type, type);
EXPECT_EQ(pSchema->bytes, bytes); EXPECT_EQ(pSchema->bytes, bytes);
...@@ -128,17 +128,14 @@ class DndTestDnode : public ::testing::Test { ...@@ -128,17 +128,14 @@ class DndTestDnode : public ::testing::Test {
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont; pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
ASSERT_NE(pRetrieveRsp, nullptr); ASSERT_NE(pRetrieveRsp, nullptr);
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
pRetrieveRsp->offset = htobe64(pRetrieveRsp->offset);
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen); pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
EXPECT_EQ(pRetrieveRsp->numOfRows, rows); EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
EXPECT_EQ(pRetrieveRsp->offset, 0);
EXPECT_EQ(pRetrieveRsp->useconds, 0); EXPECT_EQ(pRetrieveRsp->useconds, 0);
// EXPECT_EQ(pRetrieveRsp->completed, completed); // EXPECT_EQ(pRetrieveRsp->completed, completed);
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI); EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
EXPECT_EQ(pRetrieveRsp->compressed, 0); EXPECT_EQ(pRetrieveRsp->compressed, 0);
EXPECT_EQ(pRetrieveRsp->reserved, 0);
EXPECT_EQ(pRetrieveRsp->compLen, 0); EXPECT_EQ(pRetrieveRsp->compLen, 0);
pData = pRetrieveRsp->data; pData = pRetrieveRsp->data;
...@@ -187,12 +184,12 @@ SClient* DndTestDnode::pClient; ...@@ -187,12 +184,12 @@ SClient* DndTestDnode::pClient;
TEST_F(DndTestDnode, 01_ShowDnode) { TEST_F(DndTestDnode, 01_ShowDnode) {
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7); SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_DNODE, "show dnodes", 7);
CheckSchema(0, TSDB_DATA_TYPE_SMALLINT, 2, "id"); CheckSchema(0, TSDB_DATA_TYPE_SMALLINT, 2, "id");
CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "end point"); CheckSchema(1, TSDB_DATA_TYPE_BINARY, TSDB_EP_LEN + VARSTR_HEADER_SIZE, "endpoint");
CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "vnodes"); CheckSchema(2, TSDB_DATA_TYPE_SMALLINT, 2, "vnodes");
CheckSchema(3, TSDB_DATA_TYPE_SMALLINT, 2, "max vnodes"); CheckSchema(3, TSDB_DATA_TYPE_SMALLINT, 2, "max_vnodes");
CheckSchema(4, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "status"); CheckSchema(4, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "status");
CheckSchema(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create time"); CheckSchema(5, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
CheckSchema(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline reason"); CheckSchema(6, TSDB_DATA_TYPE_BINARY, 24 + VARSTR_HEADER_SIZE, "offline_reason");
SendThenCheckShowRetrieveMsg(1); SendThenCheckShowRetrieveMsg(1);
CheckInt16(1); CheckInt16(1);
......
...@@ -21,8 +21,6 @@ target_include_directories(dndTestProfile ...@@ -21,8 +21,6 @@ target_include_directories(dndTestProfile
"${CMAKE_CURRENT_SOURCE_DIR}/../sut" "${CMAKE_CURRENT_SOURCE_DIR}/../sut"
) )
enable_testing()
add_test( add_test(
NAME dndTestProfile NAME dndTestProfile
COMMAND dndTestProfile COMMAND dndTestProfile
......
/** /**
* @file vnodeApiTests.cpp * @file profile.cpp
* @author slguan (slguan@taosdata.com) * @author slguan (slguan@taosdata.com)
* @brief DNODE module profile-msg tests * @brief DNODE module profile-msg tests
* @version 0.1 * @version 0.1
...@@ -216,17 +216,14 @@ TEST_F(DndTestProfile, SConnectMsg_03) { ...@@ -216,17 +216,14 @@ TEST_F(DndTestProfile, SConnectMsg_03) {
SRetrieveTableRsp* pRsp = (SRetrieveTableRsp*)pMsg->pCont; SRetrieveTableRsp* pRsp = (SRetrieveTableRsp*)pMsg->pCont;
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
pRsp->numOfRows = htonl(pRsp->numOfRows); pRsp->numOfRows = htonl(pRsp->numOfRows);
pRsp->offset = htobe64(pRsp->offset);
pRsp->useconds = htobe64(pRsp->useconds); pRsp->useconds = htobe64(pRsp->useconds);
pRsp->compLen = htonl(pRsp->compLen); pRsp->compLen = htonl(pRsp->compLen);
EXPECT_EQ(pRsp->numOfRows, 1); EXPECT_EQ(pRsp->numOfRows, 1);
EXPECT_EQ(pRsp->offset, 0);
EXPECT_EQ(pRsp->useconds, 0); EXPECT_EQ(pRsp->useconds, 0);
EXPECT_EQ(pRsp->completed, 1); EXPECT_EQ(pRsp->completed, 1);
EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI); EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI);
EXPECT_EQ(pRsp->compressed, 0); EXPECT_EQ(pRsp->compressed, 0);
EXPECT_EQ(pRsp->reserved, 0);
EXPECT_EQ(pRsp->compLen, 0); EXPECT_EQ(pRsp->compLen, 0);
} }
} }
...@@ -497,7 +494,7 @@ TEST_F(DndTestProfile, SKillQueryMsg_03) { ...@@ -497,7 +494,7 @@ TEST_F(DndTestProfile, SKillQueryMsg_03) {
EXPECT_STREQ(pSchema->name, "queryId"); EXPECT_STREQ(pSchema->name, "queryId");
pSchema = &pMeta->pSchema[1]; pSchema = &pMeta->pSchema[1];
pSchema->bytes = htons(pSchema->bytes); pSchema->bytes = htonl(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0); EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT); EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
EXPECT_EQ(pSchema->bytes, 4); EXPECT_EQ(pSchema->bytes, 4);
......
add_executable(dndTestShow "") add_executable(dnode_test_show "")
target_sources(dndTestShow target_sources(dnode_test_show
PRIVATE PRIVATE
"show.cpp" "show.cpp"
"../sut/deploy.cpp" "../sut/deploy.cpp"
) )
target_link_libraries( target_link_libraries(
dndTestShow dnode_test_show
PUBLIC dnode PUBLIC dnode
PUBLIC util PUBLIC util
PUBLIC os PUBLIC os
PUBLIC gtest_main PUBLIC gtest_main
) )
target_include_directories(dndTestShow target_include_directories(dnode_test_show
PUBLIC PUBLIC
"${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt" "${CMAKE_SOURCE_DIR}/include/server/dnode/mgmt"
"${CMAKE_CURRENT_SOURCE_DIR}/../../inc" "${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
"${CMAKE_CURRENT_SOURCE_DIR}/../sut" "${CMAKE_CURRENT_SOURCE_DIR}/../sut"
) )
enable_testing()
add_test( add_test(
NAME dndTestShow NAME dnode_test_show
COMMAND dndTestShow COMMAND dnode_test_show
) )
/** /**
* @file vnodeApiTests.cpp * @file show.cpp
* @author slguan (slguan@taosdata.com) * @author slguan (slguan@taosdata.com)
* @brief DNODE module show-msg tests * @brief DNODE module show-msg tests
* @version 0.1 * @version 0.1
...@@ -151,49 +151,49 @@ TEST_F(DndTestShow, SShowMsg_04) { ...@@ -151,49 +151,49 @@ TEST_F(DndTestShow, SShowMsg_04) {
SSchema* pSchema = NULL; SSchema* pSchema = NULL;
pSchema = &pMeta->pSchema[0]; pSchema = &pMeta->pSchema[0];
pSchema->bytes = htons(pSchema->bytes); pSchema->bytes = htonl(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0); EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT); EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
EXPECT_EQ(pSchema->bytes, 4); EXPECT_EQ(pSchema->bytes, 4);
EXPECT_STREQ(pSchema->name, "connId"); EXPECT_STREQ(pSchema->name, "connId");
pSchema = &pMeta->pSchema[1]; pSchema = &pMeta->pSchema[1];
pSchema->bytes = htons(pSchema->bytes); pSchema->bytes = htonl(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0); EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY); EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE); EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE);
EXPECT_STREQ(pSchema->name, "user"); EXPECT_STREQ(pSchema->name, "user");
pSchema = &pMeta->pSchema[2]; pSchema = &pMeta->pSchema[2];
pSchema->bytes = htons(pSchema->bytes); pSchema->bytes = htonl(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0); EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY); EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE); EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE);
EXPECT_STREQ(pSchema->name, "program"); EXPECT_STREQ(pSchema->name, "program");
pSchema = &pMeta->pSchema[3]; pSchema = &pMeta->pSchema[3];
pSchema->bytes = htons(pSchema->bytes); pSchema->bytes = htonl(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0); EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT); EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_INT);
EXPECT_EQ(pSchema->bytes, 4); EXPECT_EQ(pSchema->bytes, 4);
EXPECT_STREQ(pSchema->name, "pid"); EXPECT_STREQ(pSchema->name, "pid");
pSchema = &pMeta->pSchema[4]; pSchema = &pMeta->pSchema[4];
pSchema->bytes = htons(pSchema->bytes); pSchema->bytes = htonl(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0); EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY); EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
EXPECT_EQ(pSchema->bytes, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE); EXPECT_EQ(pSchema->bytes, TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE);
EXPECT_STREQ(pSchema->name, "ip:port"); EXPECT_STREQ(pSchema->name, "ip:port");
pSchema = &pMeta->pSchema[5]; pSchema = &pMeta->pSchema[5];
pSchema->bytes = htons(pSchema->bytes); pSchema->bytes = htonl(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0); EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP); EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP);
EXPECT_EQ(pSchema->bytes, 8); EXPECT_EQ(pSchema->bytes, 8);
EXPECT_STREQ(pSchema->name, "login_time"); EXPECT_STREQ(pSchema->name, "login_time");
pSchema = &pMeta->pSchema[6]; pSchema = &pMeta->pSchema[6];
pSchema->bytes = htons(pSchema->bytes); pSchema->bytes = htonl(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0); EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP); EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP);
EXPECT_EQ(pSchema->bytes, 8); EXPECT_EQ(pSchema->bytes, 8);
......
add_executable(dnode_test_stb "")
target_sources(dnode_test_stb
PRIVATE
"stb.cpp"
"../sut/deploy.cpp"
)
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"
)
add_test(
NAME dnode_test_stb
COMMAND dnode_test_stb
)
/**
* @file stb.cpp
* @author slguan (slguan@taosdata.com)
* @brief DNODE module db-msg tests
* @version 0.1
* @date 2021-12-17
*
* @copyright Copyright (c) 2021
*
*/
#include "deploy.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() {
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;
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;
TEST_F(DndTestStb, 01_Create_Show_Meta_Drop_Restart_Stb) {
{
SCreateDbMsg* pReq = (SCreateDbMsg*)rpcMallocCont(sizeof(SCreateDbMsg));
strcpy(pReq->db, "1.d1");
pReq->numOfVgroups = 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->minRowsPerFileBlock = htonl(100);
pReq->maxRowsPerFileBlock = htonl(4096);
pReq->commitTime = htonl(3600);
pReq->fsyncPeriod = htonl(3000);
pReq->walLevel = 1;
pReq->precision = 0;
pReq->compression = 2;
pReq->replications = 1;
pReq->quorum = 1;
pReq->update = 0;
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;
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
}
{
int32_t cols = 2;
int32_t tags = 3;
int32_t size = (tags + cols) * sizeof(SSchema) + sizeof(SCreateStbMsg);
SCreateStbMsg* pReq = (SCreateStbMsg*)rpcMallocCont(size);
strcpy(pReq->name, "1.d1.stb");
pReq->numOfTags = htonl(tags);
pReq->numOfColumns = htonl(cols);
{
SSchema* pSchema = &pReq->pSchema[0];
pSchema->colId = htonl(0);
pSchema->bytes = htonl(8);
pSchema->type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema->name, "ts");
}
{
SSchema* pSchema = &pReq->pSchema[1];
pSchema->colId = htonl(1);
pSchema->bytes = htonl(4);
pSchema->type = TSDB_DATA_TYPE_INT;
strcpy(pSchema->name, "col1");
}
{
SSchema* pSchema = &pReq->pSchema[2];
pSchema->colId = htonl(2);
pSchema->bytes = htonl(2);
pSchema->type = TSDB_DATA_TYPE_TINYINT;
strcpy(pSchema->name, "tag1");
}
{
SSchema* pSchema = &pReq->pSchema[3];
pSchema->colId = htonl(3);
pSchema->bytes = htonl(8);
pSchema->type = TSDB_DATA_TYPE_BIGINT;
strcpy(pSchema->name, "tag2");
}
{
SSchema* pSchema = &pReq->pSchema[4];
pSchema->colId = htonl(4);
pSchema->bytes = htonl(16);
pSchema->type = TSDB_DATA_TYPE_BINARY;
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;
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");
SendThenCheckShowRetrieveMsg(1);
CheckBinary("stb", TSDB_TABLE_NAME_LEN);
CheckTimestamp();
CheckInt32(2);
CheckInt32(3);
// ----- meta ------
{
STableInfoMsg* pReq = (STableInfoMsg*)rpcMallocCont(sizeof(STableInfoMsg));
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;
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
STableMetaMsg* pRsp = (STableMetaMsg*)pMsg->pCont;
pRsp->numOfTags = htonl(pRsp->numOfTags);
pRsp->numOfColumns = htonl(pRsp->numOfColumns);
pRsp->sversion = htonl(pRsp->sversion);
pRsp->tversion = htonl(pRsp->tversion);
pRsp->suid = htobe64(pRsp->suid);
pRsp->tuid = htobe64(pRsp->tuid);
pRsp->vgId = htobe64(pRsp->vgId);
for (int32_t i = 0; i < pRsp->numOfTags + pRsp->numOfColumns; ++i) {
SSchema* pSchema = &pRsp->pSchema[i];
pSchema->colId = htonl(pSchema->colId);
pSchema->bytes = htonl(pSchema->bytes);
}
EXPECT_STREQ(pRsp->tbFname, "");
EXPECT_STREQ(pRsp->stbFname, "1.d1.stb");
EXPECT_EQ(pRsp->numOfColumns, 2);
EXPECT_EQ(pRsp->numOfTags, 3);
EXPECT_EQ(pRsp->precision, TSDB_TIME_PRECISION_MILLI);
EXPECT_EQ(pRsp->tableType, TSDB_SUPER_TABLE);
EXPECT_EQ(pRsp->update, 0);
EXPECT_EQ(pRsp->sversion, 1);
EXPECT_EQ(pRsp->tversion, 0);
EXPECT_GT(pRsp->suid, 0);
EXPECT_EQ(pRsp->tuid, 0);
EXPECT_EQ(pRsp->vgId, 0);
{
SSchema* pSchema = &pRsp->pSchema[0];
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP);
EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->bytes, 8);
EXPECT_STREQ(pSchema->name, "ts");
}
}
// restart
stopServer(pServer);
pServer = NULL;
uInfo("start all server");
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));
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;
ASSERT_NE(pMsg, nullptr);
ASSERT_EQ(pMsg->code, 0);
}
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_STB, "show stables", 4, "1.d1");
SendThenCheckShowRetrieveMsg(0);
}
...@@ -21,8 +21,6 @@ target_include_directories(dnode_test_user ...@@ -21,8 +21,6 @@ target_include_directories(dnode_test_user
"${CMAKE_CURRENT_SOURCE_DIR}/../sut" "${CMAKE_CURRENT_SOURCE_DIR}/../sut"
) )
enable_testing()
add_test( add_test(
NAME dnode_test_user NAME dnode_test_user
COMMAND dnode_test_user COMMAND dnode_test_user
......
/** /**
* @file vnodeApiTests.cpp * @file user.cpp
* @author slguan (slguan@taosdata.com) * @author slguan (slguan@taosdata.com)
* @brief DNODE module user-msg tests * @brief DNODE module user-msg tests
* @version 0.1 * @version 0.1
...@@ -87,7 +87,7 @@ class DndTestUser : public ::testing::Test { ...@@ -87,7 +87,7 @@ class DndTestUser : public ::testing::Test {
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) { void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
SSchema* pSchema = &pMeta->pSchema[index]; SSchema* pSchema = &pMeta->pSchema[index];
pSchema->bytes = htons(pSchema->bytes); pSchema->bytes = htonl(pSchema->bytes);
EXPECT_EQ(pSchema->colId, 0); EXPECT_EQ(pSchema->colId, 0);
EXPECT_EQ(pSchema->type, type); EXPECT_EQ(pSchema->type, type);
EXPECT_EQ(pSchema->bytes, bytes); EXPECT_EQ(pSchema->bytes, bytes);
...@@ -113,17 +113,14 @@ class DndTestUser : public ::testing::Test { ...@@ -113,17 +113,14 @@ class DndTestUser : public ::testing::Test {
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont; pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
ASSERT_NE(pRetrieveRsp, nullptr); ASSERT_NE(pRetrieveRsp, nullptr);
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows); pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
pRetrieveRsp->offset = htobe64(pRetrieveRsp->offset);
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds); pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen); pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
EXPECT_EQ(pRetrieveRsp->numOfRows, rows); EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
EXPECT_EQ(pRetrieveRsp->offset, 0);
EXPECT_EQ(pRetrieveRsp->useconds, 0); EXPECT_EQ(pRetrieveRsp->useconds, 0);
// EXPECT_EQ(pRetrieveRsp->completed, completed); // EXPECT_EQ(pRetrieveRsp->completed, completed);
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI); EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
EXPECT_EQ(pRetrieveRsp->compressed, 0); EXPECT_EQ(pRetrieveRsp->compressed, 0);
EXPECT_EQ(pRetrieveRsp->reserved, 0);
EXPECT_EQ(pRetrieveRsp->compLen, 0); EXPECT_EQ(pRetrieveRsp->compLen, 0);
pData = pRetrieveRsp->data; pData = pRetrieveRsp->data;
...@@ -170,7 +167,7 @@ TEST_F(DndTestUser, 01_ShowUser) { ...@@ -170,7 +167,7 @@ TEST_F(DndTestUser, 01_ShowUser) {
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4); SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "name"); 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(1, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "privilege");
CheckSchema(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create time"); CheckSchema(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create_time");
CheckSchema(3, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "account"); CheckSchema(3, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "account");
SendThenCheckShowRetrieveMsg(1); SendThenCheckShowRetrieveMsg(1);
......
...@@ -182,6 +182,7 @@ typedef struct { ...@@ -182,6 +182,7 @@ typedef struct {
} SUserObj; } SUserObj;
typedef struct { typedef struct {
int32_t numOfVgroups;
int32_t cacheBlockSize; int32_t cacheBlockSize;
int32_t totalBlocks; int32_t totalBlocks;
int32_t daysPerFile; int32_t daysPerFile;
...@@ -209,7 +210,6 @@ typedef struct { ...@@ -209,7 +210,6 @@ typedef struct {
int64_t uid; int64_t uid;
int32_t cfgVersion; int32_t cfgVersion;
int32_t vgVersion; int32_t vgVersion;
int32_t numOfVgroups;
int8_t hashMethod; // default is 1 int8_t hashMethod; // default is 1
SDbCfg cfg; SDbCfg cfg;
} SDbObj; } SDbObj;
......
...@@ -143,22 +143,22 @@ static int32_t mndGetClusterMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg ...@@ -143,22 +143,22 @@ static int32_t mndGetClusterMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "id"); strcpy(pSchema[cols].name, "id");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "name"); strcpy(pSchema[cols].name, "name");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "create_time"); strcpy(pSchema[cols].name, "create_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pMeta->numOfColumns = htons(cols); pMeta->numOfColumns = htonl(cols);
strcpy(pMeta->tbFname, mndShowStr(pShow->type)); strcpy(pMeta->tbFname, mndShowStr(pShow->type));
pShow->numOfColumns = cols; pShow->numOfColumns = cols;
......
...@@ -77,8 +77,8 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) { ...@@ -77,8 +77,8 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
SDB_SET_INT64(pRaw, dataPos, pDb->uid) SDB_SET_INT64(pRaw, dataPos, pDb->uid)
SDB_SET_INT32(pRaw, dataPos, pDb->cfgVersion) SDB_SET_INT32(pRaw, dataPos, pDb->cfgVersion)
SDB_SET_INT32(pRaw, dataPos, pDb->vgVersion) SDB_SET_INT32(pRaw, dataPos, pDb->vgVersion)
SDB_SET_INT32(pRaw, dataPos, pDb->numOfVgroups)
SDB_SET_INT8(pRaw, dataPos, pDb->hashMethod) SDB_SET_INT8(pRaw, dataPos, pDb->hashMethod)
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfVgroups)
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.cacheBlockSize) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.cacheBlockSize)
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.totalBlocks) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.totalBlocks)
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile) SDB_SET_INT32(pRaw, dataPos, pDb->cfg.daysPerFile)
...@@ -124,8 +124,8 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) { ...@@ -124,8 +124,8 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->uid) SDB_GET_INT64(pRaw, pRow, dataPos, &pDb->uid)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfgVersion) SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfgVersion)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->vgVersion) SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->vgVersion)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->numOfVgroups)
SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->hashMethod) SDB_GET_INT8(pRaw, pRow, dataPos, &pDb->hashMethod)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.numOfVgroups)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.cacheBlockSize) SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.cacheBlockSize)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.totalBlocks) SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.totalBlocks)
SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysPerFile) SDB_GET_INT32(pRaw, pRow, dataPos, &pDb->cfg.daysPerFile)
...@@ -163,7 +163,6 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOldDb, SDbObj *pNewDb) { ...@@ -163,7 +163,6 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOldDb, SDbObj *pNewDb) {
pOldDb->updateTime = pNewDb->createdTime; pOldDb->updateTime = pNewDb->createdTime;
pOldDb->cfgVersion = pNewDb->cfgVersion; pOldDb->cfgVersion = pNewDb->cfgVersion;
pOldDb->vgVersion = pNewDb->vgVersion; pOldDb->vgVersion = pNewDb->vgVersion;
pOldDb->numOfVgroups = pNewDb->numOfVgroups;
memcpy(&pOldDb->cfg, &pNewDb->cfg, sizeof(SDbCfg)); memcpy(&pOldDb->cfg, &pNewDb->cfg, sizeof(SDbCfg));
return 0; return 0;
} }
...@@ -195,6 +194,7 @@ static int32_t mndCheckDbName(char *dbName, SUserObj *pUser) { ...@@ -195,6 +194,7 @@ static int32_t mndCheckDbName(char *dbName, SUserObj *pUser) {
} }
static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
if (pCfg->numOfVgroups < TSDB_MIN_VNODES_PER_DB || pCfg->numOfVgroups > TSDB_MAX_VNODES_PER_DB) return -1;
if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) return -1; if (pCfg->cacheBlockSize < TSDB_MIN_CACHE_BLOCK_SIZE || pCfg->cacheBlockSize > TSDB_MAX_CACHE_BLOCK_SIZE) return -1;
if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) return -1; if (pCfg->totalBlocks < TSDB_MIN_TOTAL_BLOCKS || pCfg->totalBlocks > TSDB_MAX_TOTAL_BLOCKS) return -1;
if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) return -1; if (pCfg->daysPerFile < TSDB_MIN_DAYS_PER_FILE || pCfg->daysPerFile > TSDB_MAX_DAYS_PER_FILE) return -1;
...@@ -222,6 +222,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { ...@@ -222,6 +222,7 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) {
} }
static void mndSetDefaultDbCfg(SDbCfg *pCfg) { static void mndSetDefaultDbCfg(SDbCfg *pCfg) {
if (pCfg->numOfVgroups < 0) pCfg->numOfVgroups = TSDB_DEFAULT_VN_PER_DB;
if (pCfg->cacheBlockSize < 0) pCfg->cacheBlockSize = TSDB_DEFAULT_CACHE_BLOCK_SIZE; if (pCfg->cacheBlockSize < 0) pCfg->cacheBlockSize = TSDB_DEFAULT_CACHE_BLOCK_SIZE;
if (pCfg->totalBlocks < 0) pCfg->totalBlocks = TSDB_DEFAULT_TOTAL_BLOCKS; if (pCfg->totalBlocks < 0) pCfg->totalBlocks = TSDB_DEFAULT_TOTAL_BLOCKS;
if (pCfg->daysPerFile < 0) pCfg->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE; if (pCfg->daysPerFile < 0) pCfg->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE;
...@@ -246,7 +247,7 @@ static int32_t mndSetRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgOb ...@@ -246,7 +247,7 @@ static int32_t mndSetRedoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgOb
if (pDbRaw == NULL || mndTransAppendRedolog(pTrans, pDbRaw) != 0) return -1; if (pDbRaw == NULL || mndTransAppendRedolog(pTrans, pDbRaw) != 0) return -1;
sdbSetRawStatus(pDbRaw, SDB_STATUS_CREATING); sdbSetRawStatus(pDbRaw, SDB_STATUS_CREATING);
for (int v = 0; v < pDb->numOfVgroups; ++v) { for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v); SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
if (pVgRaw == NULL || mndTransAppendRedolog(pTrans, pVgRaw) != 0) return -1; if (pVgRaw == NULL || mndTransAppendRedolog(pTrans, pVgRaw) != 0) return -1;
sdbSetRawStatus(pVgRaw, SDB_STATUS_CREATING); sdbSetRawStatus(pVgRaw, SDB_STATUS_CREATING);
...@@ -260,7 +261,7 @@ static int32_t mndSetUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgOb ...@@ -260,7 +261,7 @@ static int32_t mndSetUndoLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgOb
if (pDbRaw == NULL || mndTransAppendUndolog(pTrans, pDbRaw) != 0) return -1; if (pDbRaw == NULL || mndTransAppendUndolog(pTrans, pDbRaw) != 0) return -1;
sdbSetRawStatus(pDbRaw, SDB_STATUS_DROPPED); sdbSetRawStatus(pDbRaw, SDB_STATUS_DROPPED);
for (int v = 0; v < pDb->numOfVgroups; ++v) { for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v); SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
if (pVgRaw == NULL || mndTransAppendUndolog(pTrans, pVgRaw) != 0) return -1; if (pVgRaw == NULL || mndTransAppendUndolog(pTrans, pVgRaw) != 0) return -1;
sdbSetRawStatus(pVgRaw, SDB_STATUS_DROPPED); sdbSetRawStatus(pVgRaw, SDB_STATUS_DROPPED);
...@@ -274,7 +275,7 @@ static int32_t mndSetCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVg ...@@ -274,7 +275,7 @@ static int32_t mndSetCommitLogs(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVg
if (pDbRaw == NULL || mndTransAppendCommitlog(pTrans, pDbRaw) != 0) return -1; if (pDbRaw == NULL || mndTransAppendCommitlog(pTrans, pDbRaw) != 0) return -1;
sdbSetRawStatus(pDbRaw, SDB_STATUS_READY); sdbSetRawStatus(pDbRaw, SDB_STATUS_READY);
for (int v = 0; v < pDb->numOfVgroups; ++v) { for (int v = 0; v < pDb->cfg.numOfVgroups; ++v) {
SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v); SSdbRaw *pVgRaw = mndVgroupActionEncode(pVgroups + v);
if (pVgRaw == NULL || mndTransAppendCommitlog(pTrans, pVgRaw) != 0) return -1; if (pVgRaw == NULL || mndTransAppendCommitlog(pTrans, pVgRaw) != 0) return -1;
sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
...@@ -298,11 +299,11 @@ static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreat ...@@ -298,11 +299,11 @@ static int32_t mndCreateDb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateDbMsg *pCreat
dbObj.createdTime = taosGetTimestampMs(); dbObj.createdTime = taosGetTimestampMs();
dbObj.updateTime = dbObj.createdTime; dbObj.updateTime = dbObj.createdTime;
dbObj.uid = mndGenerateUid(dbObj.name, TSDB_FULL_DB_NAME_LEN); dbObj.uid = mndGenerateUid(dbObj.name, TSDB_FULL_DB_NAME_LEN);
dbObj.numOfVgroups = pCreate->numOfVgroups;
dbObj.hashMethod = 1; dbObj.hashMethod = 1;
dbObj.cfgVersion = 1; dbObj.cfgVersion = 1;
dbObj.vgVersion = 1; dbObj.vgVersion = 1;
dbObj.cfg = (SDbCfg){.cacheBlockSize = pCreate->cacheBlockSize, dbObj.cfg = (SDbCfg){.numOfVgroups = pCreate->numOfVgroups,
.cacheBlockSize = pCreate->cacheBlockSize,
.totalBlocks = pCreate->totalBlocks, .totalBlocks = pCreate->totalBlocks,
.daysPerFile = pCreate->daysPerFile, .daysPerFile = pCreate->daysPerFile,
.daysToKeep0 = pCreate->daysToKeep0, .daysToKeep0 = pCreate->daysToKeep0,
...@@ -643,7 +644,7 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) { ...@@ -643,7 +644,7 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) {
return -1; return -1;
} }
int32_t contLen = sizeof(SUseDbRsp) + pDb->numOfVgroups * sizeof(SVgroupInfo); int32_t contLen = sizeof(SUseDbRsp) + pDb->cfg.numOfVgroups * sizeof(SVgroupInfo);
SUseDbRsp *pRsp = rpcMallocCont(contLen); SUseDbRsp *pRsp = rpcMallocCont(contLen);
if (pRsp == NULL) { if (pRsp == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
...@@ -654,7 +655,7 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) { ...@@ -654,7 +655,7 @@ static int32_t mndProcessUseDbMsg(SMnodeMsg *pMsg) {
if (pUse->vgVersion < pDb->vgVersion) { if (pUse->vgVersion < pDb->vgVersion) {
void *pIter = NULL; void *pIter = NULL;
while (vindex < pDb->numOfVgroups) { while (vindex < pDb->cfg.numOfVgroups) {
SVgObj *pVgroup = NULL; SVgObj *pVgroup = NULL;
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
if (pIter == NULL) break; if (pIter == NULL) break;
...@@ -735,103 +736,103 @@ static int32_t mndGetDbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMe ...@@ -735,103 +736,103 @@ static int32_t mndGetDbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMe
pShow->bytes[cols] = (TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE; pShow->bytes[cols] = (TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "name"); strcpy(pSchema[cols].name, "name");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "create time"); strcpy(pSchema[cols].name, "create_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 2; pShow->bytes[cols] = 2;
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
strcpy(pSchema[cols].name, "vgroups"); strcpy(pSchema[cols].name, "vgroups");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 2; pShow->bytes[cols] = 2;
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
strcpy(pSchema[cols].name, "replica"); strcpy(pSchema[cols].name, "replica");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 2; pShow->bytes[cols] = 2;
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
strcpy(pSchema[cols].name, "quorum"); strcpy(pSchema[cols].name, "quorum");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 2; pShow->bytes[cols] = 2;
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
strcpy(pSchema[cols].name, "days"); strcpy(pSchema[cols].name, "days");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 24 + VARSTR_HEADER_SIZE; pShow->bytes[cols] = 24 + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "keep0,keep1,keep2"); strcpy(pSchema[cols].name, "keep0,keep1,keep2");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "cache(MB)"); strcpy(pSchema[cols].name, "cache");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "blocks"); strcpy(pSchema[cols].name, "blocks");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "minrows"); strcpy(pSchema[cols].name, "minrows");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "maxrows"); strcpy(pSchema[cols].name, "maxrows");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 1; pShow->bytes[cols] = 1;
pSchema[cols].type = TSDB_DATA_TYPE_TINYINT; pSchema[cols].type = TSDB_DATA_TYPE_TINYINT;
strcpy(pSchema[cols].name, "wallevel"); strcpy(pSchema[cols].name, "wallevel");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "fsync"); strcpy(pSchema[cols].name, "fsync");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 1; pShow->bytes[cols] = 1;
pSchema[cols].type = TSDB_DATA_TYPE_TINYINT; pSchema[cols].type = TSDB_DATA_TYPE_TINYINT;
strcpy(pSchema[cols].name, "comp"); strcpy(pSchema[cols].name, "comp");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 1; pShow->bytes[cols] = 1;
pSchema[cols].type = TSDB_DATA_TYPE_TINYINT; pSchema[cols].type = TSDB_DATA_TYPE_TINYINT;
strcpy(pSchema[cols].name, "cachelast"); strcpy(pSchema[cols].name, "cachelast");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 3 + VARSTR_HEADER_SIZE; pShow->bytes[cols] = 3 + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "precision"); strcpy(pSchema[cols].name, "precision");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 1; pShow->bytes[cols] = 1;
pSchema[cols].type = TSDB_DATA_TYPE_TINYINT; pSchema[cols].type = TSDB_DATA_TYPE_TINYINT;
strcpy(pSchema[cols].name, "update"); strcpy(pSchema[cols].name, "update");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pMeta->numOfColumns = htonl(cols); pMeta->numOfColumns = htonl(cols);
...@@ -888,7 +889,7 @@ static int32_t mndRetrieveDbs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3 ...@@ -888,7 +889,7 @@ static int32_t mndRetrieveDbs(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int16_t *)pWrite = pDb->numOfVgroups; *(int16_t *)pWrite = pDb->cfg.numOfVgroups;
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
......
...@@ -561,13 +561,13 @@ static int32_t mndGetConfigMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg ...@@ -561,13 +561,13 @@ static int32_t mndGetConfigMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg
pShow->bytes[cols] = TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_CONFIG_OPTION_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
tstrncpy(pSchema[cols].name, "name", sizeof(pSchema[cols].name)); tstrncpy(pSchema[cols].name, "name", sizeof(pSchema[cols].name));
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_CONIIG_VALUE_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
tstrncpy(pSchema[cols].name, "value", sizeof(pSchema[cols].name)); tstrncpy(pSchema[cols].name, "value", sizeof(pSchema[cols].name));
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pMeta->numOfColumns = htonl(cols); pMeta->numOfColumns = htonl(cols);
...@@ -638,43 +638,43 @@ static int32_t mndGetDnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * ...@@ -638,43 +638,43 @@ static int32_t mndGetDnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
pShow->bytes[cols] = 2; pShow->bytes[cols] = 2;
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
strcpy(pSchema[cols].name, "id"); strcpy(pSchema[cols].name, "id");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "end point"); strcpy(pSchema[cols].name, "endpoint");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 2; pShow->bytes[cols] = 2;
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
strcpy(pSchema[cols].name, "vnodes"); strcpy(pSchema[cols].name, "vnodes");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 2; pShow->bytes[cols] = 2;
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
strcpy(pSchema[cols].name, "max vnodes"); strcpy(pSchema[cols].name, "max_vnodes");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 10 + VARSTR_HEADER_SIZE; pShow->bytes[cols] = 10 + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "status"); strcpy(pSchema[cols].name, "status");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "create time"); strcpy(pSchema[cols].name, "create_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 24 + VARSTR_HEADER_SIZE; pShow->bytes[cols] = 24 + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "offline reason"); strcpy(pSchema[cols].name, "offline_reason");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pMeta->numOfColumns = htonl(cols); pMeta->numOfColumns = htonl(cols);
......
...@@ -380,43 +380,43 @@ static int32_t mndGetFuncMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *p ...@@ -380,43 +380,43 @@ static int32_t mndGetFuncMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *p
pShow->bytes[cols] = TSDB_FUNC_NAME_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_FUNC_NAME_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "name"); strcpy(pSchema[cols].name, "name");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = PATH_MAX + VARSTR_HEADER_SIZE; pShow->bytes[cols] = PATH_MAX + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "comment"); strcpy(pSchema[cols].name, "comment");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "aggregate"); strcpy(pSchema[cols].name, "aggregate");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_TYPE_STR_MAX_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_TYPE_STR_MAX_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "outputtype"); strcpy(pSchema[cols].name, "outputtype");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "create_time"); strcpy(pSchema[cols].name, "create_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "code_len"); strcpy(pSchema[cols].name, "code_len");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "bufsize"); strcpy(pSchema[cols].name, "bufsize");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pMeta->numOfColumns = htonl(cols); pMeta->numOfColumns = htonl(cols);
......
...@@ -368,31 +368,31 @@ static int32_t mndGetMnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * ...@@ -368,31 +368,31 @@ static int32_t mndGetMnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
pShow->bytes[cols] = 2; pShow->bytes[cols] = 2;
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
strcpy(pSchema[cols].name, "id"); strcpy(pSchema[cols].name, "id");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "end point"); strcpy(pSchema[cols].name, "endpoint");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 12 + VARSTR_HEADER_SIZE; pShow->bytes[cols] = 12 + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "role"); strcpy(pSchema[cols].name, "role");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "role time"); strcpy(pSchema[cols].name, "role_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "create time"); strcpy(pSchema[cols].name, "create_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pMeta->numOfColumns = htonl(cols); pMeta->numOfColumns = htonl(cols);
......
...@@ -474,45 +474,45 @@ static int32_t mndGetConnsMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * ...@@ -474,45 +474,45 @@ static int32_t mndGetConnsMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "connId"); strcpy(pSchema[cols].name, "connId");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "user"); strcpy(pSchema[cols].name, "user");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
// app name // app name
pShow->bytes[cols] = TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "program"); strcpy(pSchema[cols].name, "program");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
// app pid // app pid
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "pid"); strcpy(pSchema[cols].name, "pid");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "ip:port"); strcpy(pSchema[cols].name, "ip:port");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "login_time"); strcpy(pSchema[cols].name, "login_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "last_access"); strcpy(pSchema[cols].name, "last_access");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pMeta->numOfColumns = htonl(cols); pMeta->numOfColumns = htonl(cols);
...@@ -602,85 +602,85 @@ static int32_t mndGetQueryMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * ...@@ -602,85 +602,85 @@ static int32_t mndGetQueryMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "queryId"); strcpy(pSchema[cols].name, "queryId");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "connId"); strcpy(pSchema[cols].name, "connId");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "user"); strcpy(pSchema[cols].name, "user");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "ip:port"); strcpy(pSchema[cols].name, "ip:port");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 24; pShow->bytes[cols] = 24;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "qid"); strcpy(pSchema[cols].name, "qid");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "created_time"); strcpy(pSchema[cols].name, "created_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_BIGINT; pSchema[cols].type = TSDB_DATA_TYPE_BIGINT;
strcpy(pSchema[cols].name, "time"); strcpy(pSchema[cols].name, "time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = QUERY_OBJ_ID_SIZE + VARSTR_HEADER_SIZE; pShow->bytes[cols] = QUERY_OBJ_ID_SIZE + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "sql_obj_id"); strcpy(pSchema[cols].name, "sql_obj_id");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "pid"); strcpy(pSchema[cols].name, "pid");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "ep"); strcpy(pSchema[cols].name, "ep");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 1; pShow->bytes[cols] = 1;
pSchema[cols].type = TSDB_DATA_TYPE_BOOL; pSchema[cols].type = TSDB_DATA_TYPE_BOOL;
strcpy(pSchema[cols].name, "stable_query"); strcpy(pSchema[cols].name, "stable_query");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "sub_queries"); strcpy(pSchema[cols].name, "sub_queries");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "sub_query_info"); strcpy(pSchema[cols].name, "sub_query_info");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "sql"); strcpy(pSchema[cols].name, "sql");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pMeta->numOfColumns = htonl(cols); pMeta->numOfColumns = htonl(cols);
...@@ -818,61 +818,61 @@ static int32_t mndGetStreamMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg ...@@ -818,61 +818,61 @@ static int32_t mndGetStreamMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "streamId"); strcpy(pSchema[cols].name, "streamId");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "connId"); strcpy(pSchema[cols].name, "connId");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "user"); strcpy(pSchema[cols].name, "user");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "dest table"); strcpy(pSchema[cols].name, "destination");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "ip:port"); strcpy(pSchema[cols].name, "ip:port");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "created time"); strcpy(pSchema[cols].name, "create_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "exec time"); strcpy(pSchema[cols].name, "exec");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_BIGINT; pSchema[cols].type = TSDB_DATA_TYPE_BIGINT;
strcpy(pSchema[cols].name, "time(us)"); strcpy(pSchema[cols].name, "time(us)");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "sql"); strcpy(pSchema[cols].name, "sql");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "cycles"); strcpy(pSchema[cols].name, "cycles");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pMeta->numOfColumns = htonl(cols); pMeta->numOfColumns = htonl(cols);
......
...@@ -291,7 +291,7 @@ char *mndShowStr(int32_t showType) { ...@@ -291,7 +291,7 @@ char *mndShowStr(int32_t showType) {
case TSDB_MGMT_TABLE_VNODES: case TSDB_MGMT_TABLE_VNODES:
return "show vnodes"; return "show vnodes";
case TSDB_MGMT_TABLE_CLUSTER: case TSDB_MGMT_TABLE_CLUSTER:
return "show clusters"; return "show cluster";
case TSDB_MGMT_TABLE_STREAMTABLES: case TSDB_MGMT_TABLE_STREAMTABLES:
return "show streamtables"; return "show streamtables";
case TSDB_MGMT_TABLE_TP: case TSDB_MGMT_TABLE_TP:
......
...@@ -80,7 +80,7 @@ static SSdbRaw *mndStbActionEncode(SStbObj *pStb) { ...@@ -80,7 +80,7 @@ static SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
SDB_SET_INT64(pRaw, dataPos, pStb->updateTime) SDB_SET_INT64(pRaw, dataPos, pStb->updateTime)
SDB_SET_INT64(pRaw, dataPos, pStb->uid) SDB_SET_INT64(pRaw, dataPos, pStb->uid)
SDB_SET_INT64(pRaw, dataPos, pStb->dbUid) SDB_SET_INT64(pRaw, dataPos, pStb->dbUid)
SDB_SET_INT64(pRaw, dataPos, pStb->version) SDB_SET_INT32(pRaw, dataPos, pStb->version)
SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns) SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns)
SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags) SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags)
...@@ -157,11 +157,17 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOldStb, SStbObj *pNewStb ...@@ -157,11 +157,17 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOldStb, SStbObj *pNewStb
atomic_exchange_32(&pOldStb->version, pNewStb->version); atomic_exchange_32(&pOldStb->version, pNewStb->version);
taosWLockLatch(&pOldStb->lock); taosWLockLatch(&pOldStb->lock);
pOldStb->numOfColumns = pNewStb->numOfColumns;
pOldStb->numOfTags = pNewStb->numOfTags;
int32_t totalCols = pNewStb->numOfTags + pNewStb->numOfColumns; int32_t totalCols = pNewStb->numOfTags + pNewStb->numOfColumns;
int32_t totalSize = totalCols * sizeof(SSchema); int32_t totalSize = totalCols * sizeof(SSchema);
if (pOldStb->numOfTags + pOldStb->numOfColumns < totalCols) { if (pOldStb->numOfTags + pOldStb->numOfColumns < totalCols) {
pOldStb->pSchema = malloc(totalSize); void *pSchema = malloc(totalSize);
if (pSchema != NULL) {
free(pOldStb->pSchema);
pOldStb->pSchema = pSchema;
}
} }
memcpy(pOldStb->pSchema, pNewStb->pSchema, totalSize); memcpy(pOldStb->pSchema, pNewStb->pSchema, totalSize);
...@@ -200,37 +206,37 @@ static int32_t mndCheckStbMsg(SCreateStbMsg *pCreate) { ...@@ -200,37 +206,37 @@ static int32_t mndCheckStbMsg(SCreateStbMsg *pCreate) {
} }
if (pCreate->igExists < 0 || pCreate->igExists > 1) { if (pCreate->igExists < 0 || pCreate->igExists > 1) {
terrno = TSDB_CODE_MND_STB_INVALID_IGEXIST; terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
return -1; return -1;
} }
if (pCreate->numOfColumns < TSDB_MIN_COLUMNS || pCreate->numOfColumns > TSDB_MAX_COLUMNS) { if (pCreate->numOfColumns < TSDB_MIN_COLUMNS || pCreate->numOfColumns > TSDB_MAX_COLUMNS) {
terrno = TSDB_CODE_MND_STB_INVALID_COLS_NUM; terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
return -1; return -1;
} }
if (pCreate->numOfTags <= 0 || pCreate->numOfTags > TSDB_MAX_TAGS) { if (pCreate->numOfTags <= 0 || pCreate->numOfTags > TSDB_MAX_TAGS) {
terrno = TSDB_CODE_MND_STB_INVALID_TAGS_NUM; terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
return -1; return -1;
} }
int32_t maxColId = (TSDB_MAX_COLUMNS + TSDB_MAX_TAGS); int32_t maxColId = (TSDB_MAX_COLUMNS + TSDB_MAX_TAGS);
for (int32_t i = 0; i < totalCols; ++i) { for (int32_t i = 0; i < totalCols; ++i) {
SSchema *pSchema = &pCreate->pSchema[i]; SSchema *pSchema = &pCreate->pSchema[i];
if (pSchema->type <= 0) { if (pSchema->type < 0) {
terrno = TSDB_CODE_MND_STB_INVALID_COL_TYPE; terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
return -1; return -1;
} }
if (pSchema->colId < 0 || pSchema->colId >= maxColId) { if (pSchema->colId < 0 || pSchema->colId >= maxColId) {
terrno = TSDB_CODE_MND_STB_INVALID_COL_ID; terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
return -1; return -1;
} }
if (pSchema->bytes <= 0) { if (pSchema->bytes <= 0) {
terrno = TSDB_CODE_MND_STB_INVALID_COL_BYTES; terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
return -1; return -1;
} }
if (pSchema->name[0] == 0) { if (pSchema->name[0] == 0) {
terrno = TSDB_CODE_MND_STB_INVALID_COL_NAME; terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
return -1; return -1;
} }
} }
...@@ -245,6 +251,7 @@ static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateStbMsg *pCre ...@@ -245,6 +251,7 @@ static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateStbMsg *pCre
stbObj.createdTime = taosGetTimestampMs(); stbObj.createdTime = taosGetTimestampMs();
stbObj.updateTime = stbObj.createdTime; stbObj.updateTime = stbObj.createdTime;
stbObj.uid = mndGenerateUid(pCreate->name, TSDB_TABLE_FNAME_LEN); stbObj.uid = mndGenerateUid(pCreate->name, TSDB_TABLE_FNAME_LEN);
stbObj.dbUid = pDb->uid;
stbObj.version = 1; stbObj.version = 1;
stbObj.numOfColumns = pCreate->numOfColumns; stbObj.numOfColumns = pCreate->numOfColumns;
stbObj.numOfTags = pCreate->numOfTags; stbObj.numOfTags = pCreate->numOfTags;
...@@ -350,19 +357,19 @@ static int32_t mndCheckAlterStbMsg(SAlterStbMsg *pAlter) { ...@@ -350,19 +357,19 @@ static int32_t mndCheckAlterStbMsg(SAlterStbMsg *pAlter) {
pSchema->bytes = htonl(pSchema->bytes); pSchema->bytes = htonl(pSchema->bytes);
if (pSchema->type <= 0) { if (pSchema->type <= 0) {
terrno = TSDB_CODE_MND_STB_INVALID_COL_TYPE; terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
return -1; return -1;
} }
if (pSchema->colId < 0 || pSchema->colId >= (TSDB_MAX_COLUMNS + TSDB_MAX_TAGS)) { if (pSchema->colId < 0 || pSchema->colId >= (TSDB_MAX_COLUMNS + TSDB_MAX_TAGS)) {
terrno = TSDB_CODE_MND_STB_INVALID_COL_ID; terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
return -1; return -1;
} }
if (pSchema->bytes <= 0) { if (pSchema->bytes <= 0) {
terrno = TSDB_CODE_MND_STB_INVALID_COL_BYTES; terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
return -1; return -1;
} }
if (pSchema->name[0] == 0) { if (pSchema->name[0] == 0) {
terrno = TSDB_CODE_MND_STB_INVALID_COL_NAME; terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
return -1; return -1;
} }
...@@ -481,30 +488,36 @@ static int32_t mndProcessDropStbInRsp(SMnodeMsg *pMsg) { return 0; } ...@@ -481,30 +488,36 @@ static int32_t mndProcessDropStbInRsp(SMnodeMsg *pMsg) { return 0; }
static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) { static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) {
SMnode *pMnode = pMsg->pMnode; SMnode *pMnode = pMsg->pMnode;
SStbInfoMsg *pInfo = pMsg->rpcMsg.pCont; STableInfoMsg *pInfo = pMsg->rpcMsg.pCont;
mDebug("stb:%s, start to retrieve meta", pInfo->name); mDebug("stb:%s, start to retrieve meta", pInfo->tableFname);
SDbObj *pDb = mndAcquireDbByStb(pMnode, pInfo->name); SDbObj *pDb = mndAcquireDbByStb(pMnode, pInfo->tableFname);
if (pDb == NULL) { if (pDb == NULL) {
terrno = TSDB_CODE_MND_DB_NOT_SELECTED; terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
mError("stb:%s, failed to retrieve meta since %s", pInfo->name, terrstr()); mError("stb:%s, failed to retrieve meta since %s", pInfo->tableFname, terrstr());
return -1; return -1;
} }
SStbObj *pStb = mndAcquireStb(pMnode, pInfo->name); SStbObj *pStb = mndAcquireStb(pMnode, pInfo->tableFname);
if (pStb == NULL) { if (pStb == NULL) {
mndReleaseDb(pMnode, pDb); mndReleaseDb(pMnode, pDb);
terrno = TSDB_CODE_MND_INVALID_TABLE_NAME; terrno = TSDB_CODE_MND_INVALID_STB;
mError("stb:%s, failed to get meta since %s", pInfo->name, terrstr()); mError("stb:%s, failed to get meta since %s", pInfo->tableFname, terrstr());
return -1; return -1;
} }
int32_t contLen = sizeof(STableMetaMsg) + (pStb->numOfColumns + pStb->numOfTags) * sizeof(SSchema); taosRLockLatch(&pStb->lock);
int32_t totalCols = pStb->numOfColumns + pStb->numOfTags;
int32_t contLen = sizeof(STableMetaMsg) + totalCols * sizeof(SSchema);
STableMetaMsg *pMeta = rpcMallocCont(contLen); STableMetaMsg *pMeta = rpcMallocCont(contLen);
if (pMeta == NULL) { if (pMeta == NULL) {
taosRUnLockLatch(&pStb->lock);
mndReleaseDb(pMnode, pDb);
mndReleaseStb(pMnode, pStb);
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
mError("stb:%s, failed to get meta since %s", pInfo->name, terrstr()); mError("stb:%s, failed to get meta since %s", pInfo->tableFname, terrstr());
return -1; return -1;
} }
...@@ -517,7 +530,7 @@ static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) { ...@@ -517,7 +530,7 @@ static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) {
pMeta->sversion = htonl(pStb->version); pMeta->sversion = htonl(pStb->version);
pMeta->suid = htonl(pStb->uid); pMeta->suid = htonl(pStb->uid);
for (int32_t i = 0; i < pStb->numOfColumns; ++i) { for (int32_t i = 0; i < totalCols; ++i) {
SSchema *pSchema = &pMeta->pSchema[i]; SSchema *pSchema = &pMeta->pSchema[i];
SSchema *pSrcSchema = &pStb->pSchema[i]; SSchema *pSrcSchema = &pStb->pSchema[i];
memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN); memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN);
...@@ -525,11 +538,14 @@ static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) { ...@@ -525,11 +538,14 @@ static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) {
pSchema->colId = htonl(pSrcSchema->colId); pSchema->colId = htonl(pSrcSchema->colId);
pSchema->bytes = htonl(pSrcSchema->bytes); pSchema->bytes = htonl(pSrcSchema->bytes);
} }
taosRUnLockLatch(&pStb->lock);
mndReleaseDb(pMnode, pDb);
mndReleaseStb(pMnode, pStb);
pMsg->pCont = pMeta; pMsg->pCont = pMeta;
pMsg->contLen = contLen; pMsg->contLen = contLen;
mDebug("stb:%s, meta is retrieved, cols:%d tags:%d", pInfo->name, pStb->numOfColumns, pStb->numOfTags); mDebug("stb:%s, meta is retrieved, cols:%d tags:%d", pInfo->tableFname, pStb->numOfColumns, pStb->numOfTags);
return 0; return 0;
} }
...@@ -546,7 +562,7 @@ static int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs ...@@ -546,7 +562,7 @@ static int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs
void *pIter = NULL; void *pIter = NULL;
while (1) { while (1) {
SStbObj *pStb = NULL; SStbObj *pStb = NULL;
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pStb); pIter = sdbFetch(pSdb, SDB_STB, pIter, (void **)&pStb);
if (pIter == NULL) break; if (pIter == NULL) break;
if (strcmp(pStb->db, dbName) == 0) { if (strcmp(pStb->db, dbName) == 0) {
...@@ -574,25 +590,25 @@ static int32_t mndGetStbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pM ...@@ -574,25 +590,25 @@ static int32_t mndGetStbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pM
pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "name"); strcpy(pSchema[cols].name, "name");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "create time"); strcpy(pSchema[cols].name, "create_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 2; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "columns"); strcpy(pSchema[cols].name, "columns");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 2; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "tags"); strcpy(pSchema[cols].name, "tags");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pMeta->numOfColumns = htonl(cols); pMeta->numOfColumns = htonl(cols);
...@@ -603,6 +619,7 @@ static int32_t mndGetStbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pM ...@@ -603,6 +619,7 @@ static int32_t mndGetStbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pM
pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1]; pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
} }
pShow->numOfRows = sdbGetSize(pSdb, SDB_STB);
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1]; pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
strcpy(pMeta->tbFname, mndShowStr(pShow->type)); strcpy(pMeta->tbFname, mndShowStr(pShow->type));
...@@ -646,8 +663,8 @@ static int32_t mndRetrieveStb(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3 ...@@ -646,8 +663,8 @@ static int32_t mndRetrieveStb(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3
cols = 0; cols = 0;
char stbName[TSDB_TABLE_FNAME_LEN] = {0}; char stbName[TSDB_TABLE_NAME_LEN] = {0};
memcpy(stbName, pStb->name + prefixLen, TSDB_TABLE_FNAME_LEN - prefixLen); tstrncpy(stbName, pStb->name + prefixLen, TSDB_TABLE_NAME_LEN);
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
STR_TO_VARSTR(pWrite, stbName); STR_TO_VARSTR(pWrite, stbName);
cols++; cols++;
...@@ -657,11 +674,11 @@ static int32_t mndRetrieveStb(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3 ...@@ -657,11 +674,11 @@ static int32_t mndRetrieveStb(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int3
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int16_t *)pWrite = pStb->numOfColumns; *(int32_t *)pWrite = pStb->numOfColumns;
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
*(int16_t *)pWrite = pStb->numOfTags; *(int32_t *)pWrite = pStb->numOfTags;
cols++; cols++;
numOfRows++; numOfRows++;
......
...@@ -410,25 +410,25 @@ static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *p ...@@ -410,25 +410,25 @@ static int32_t mndGetUserMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *p
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "name"); strcpy(pSchema[cols].name, "name");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 10 + VARSTR_HEADER_SIZE; pShow->bytes[cols] = 10 + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "privilege"); strcpy(pSchema[cols].name, "privilege");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 8; pShow->bytes[cols] = 8;
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP; pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
strcpy(pSchema[cols].name, "create time"); strcpy(pSchema[cols].name, "create_time");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE; pShow->bytes[cols] = TSDB_USER_LEN + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "account"); strcpy(pSchema[cols].name, "account");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pMeta->numOfColumns = htonl(cols); pMeta->numOfColumns = htonl(cols);
......
...@@ -156,11 +156,6 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup) { ...@@ -156,11 +156,6 @@ void mndReleaseVgroup(SMnode *pMnode, SVgObj *pVgroup) {
sdbRelease(pSdb, pVgroup); sdbRelease(pSdb, pVgroup);
} }
static int32_t mndGetDefaultVgroupSize(SMnode *pMnode) {
// todo
return 2;
}
static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup) { static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup) {
SSdb *pSdb = pMnode->pSdb; SSdb *pSdb = pMnode->pSdb;
int32_t allocedVnodes = 0; int32_t allocedVnodes = 0;
...@@ -193,21 +188,7 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup) { ...@@ -193,21 +188,7 @@ static int32_t mndGetAvailableDnode(SMnode *pMnode, SVgObj *pVgroup) {
} }
int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) { int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
if (pDb->numOfVgroups != -1 && SVgObj *pVgroups = calloc(pDb->cfg.numOfVgroups, sizeof(SVgObj));
(pDb->numOfVgroups < TSDB_MIN_VNODES_PER_DB || pDb->numOfVgroups > TSDB_MAX_VNODES_PER_DB)) {
terrno = TSDB_CODE_MND_INVALID_DB_OPTION;
return -1;
}
if (pDb->numOfVgroups == -1) {
pDb->numOfVgroups = mndGetDefaultVgroupSize(pMnode);
if (pDb->numOfVgroups < 0) {
terrno = TSDB_CODE_MND_NO_ENOUGH_DNODES;
return -1;
}
}
SVgObj *pVgroups = calloc(pDb->numOfVgroups, sizeof(SVgObj));
if (pVgroups == NULL) { if (pVgroups == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
return -1; return -1;
...@@ -217,9 +198,9 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) { ...@@ -217,9 +198,9 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
int32_t maxVgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP); int32_t maxVgId = sdbGetMaxId(pMnode->pSdb, SDB_VGROUP);
uint32_t hashMin = 0; uint32_t hashMin = 0;
uint32_t hashMax = UINT32_MAX; uint32_t hashMax = UINT32_MAX;
uint32_t hashInterval = (hashMax - hashMin) / pDb->numOfVgroups; uint32_t hashInterval = (hashMax - hashMin) / pDb->cfg.numOfVgroups;
for (uint32_t v = 0; v < pDb->numOfVgroups; v++) { for (uint32_t v = 0; v < pDb->cfg.numOfVgroups; v++) {
SVgObj *pVgroup = &pVgroups[v]; SVgObj *pVgroup = &pVgroups[v];
pVgroup->vgId = maxVgId++; pVgroup->vgId = maxVgId++;
pVgroup->createdTime = taosGetTimestampMs(); pVgroup->createdTime = taosGetTimestampMs();
...@@ -227,7 +208,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) { ...@@ -227,7 +208,7 @@ int32_t mndAllocVgroup(SMnode *pMnode, SDbObj *pDb, SVgObj **ppVgroups) {
pVgroup->version = 1; pVgroup->version = 1;
pVgroup->dbUid = pDb->uid; pVgroup->dbUid = pDb->uid;
pVgroup->hashBegin = hashMin + hashInterval * v; pVgroup->hashBegin = hashMin + hashInterval * v;
if (v == pDb->numOfVgroups - 1) { if (v == pDb->cfg.numOfVgroups - 1) {
pVgroup->hashEnd = hashMax; pVgroup->hashEnd = hashMax;
} else { } else {
pVgroup->hashEnd = hashMin + hashInterval * (v + 1) - 1; pVgroup->hashEnd = hashMin + hashInterval * (v + 1) - 1;
...@@ -300,26 +281,26 @@ static int32_t mndGetVgroupMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg ...@@ -300,26 +281,26 @@ static int32_t mndGetVgroupMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "vgId"); strcpy(pSchema[cols].name, "vgId");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "tables"); strcpy(pSchema[cols].name, "tables");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
for (int32_t i = 0; i < pShow->replica; ++i) { for (int32_t i = 0; i < pShow->replica; ++i) {
pShow->bytes[cols] = 2; pShow->bytes[cols] = 2;
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT; pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
snprintf(pSchema[cols].name, TSDB_COL_NAME_LEN, "v%d_dnode", i + 1); snprintf(pSchema[cols].name, TSDB_COL_NAME_LEN, "v%d_dnode", i + 1);
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 9 + VARSTR_HEADER_SIZE; pShow->bytes[cols] = 9 + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
snprintf(pSchema[cols].name, TSDB_COL_NAME_LEN, "v%d_status", i + 1); snprintf(pSchema[cols].name, TSDB_COL_NAME_LEN, "v%d_status", i + 1);
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
} }
...@@ -402,13 +383,13 @@ static int32_t mndGetVnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg * ...@@ -402,13 +383,13 @@ static int32_t mndGetVnodeMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *
pShow->bytes[cols] = 4; pShow->bytes[cols] = 4;
pSchema[cols].type = TSDB_DATA_TYPE_INT; pSchema[cols].type = TSDB_DATA_TYPE_INT;
strcpy(pSchema[cols].name, "vgId"); strcpy(pSchema[cols].name, "vgId");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pShow->bytes[cols] = 12 + VARSTR_HEADER_SIZE; pShow->bytes[cols] = 12 + VARSTR_HEADER_SIZE;
pSchema[cols].type = TSDB_DATA_TYPE_BINARY; pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
strcpy(pSchema[cols].name, "status"); strcpy(pSchema[cols].name, "status");
pSchema[cols].bytes = htons(pShow->bytes[cols]); pSchema[cols].bytes = htonl(pShow->bytes[cols]);
cols++; cols++;
pMeta->numOfColumns = htonl(cols); pMeta->numOfColumns = htonl(cols);
......
...@@ -32,6 +32,8 @@ int vnodeBufPoolRecycle(SVnode *pVnode); ...@@ -32,6 +32,8 @@ int vnodeBufPoolRecycle(SVnode *pVnode);
void *vnodeMalloc(SVnode *pVnode, uint64_t size); void *vnodeMalloc(SVnode *pVnode, uint64_t size);
bool vnodeBufPoolIsFull(SVnode *pVnode); bool vnodeBufPoolIsFull(SVnode *pVnode);
SMemAllocatorFactory *vBufPoolGetMAF(SVnode *pVnode);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "mallocator.h" #include "mallocator.h"
#include "sync.h" #include "sync.h"
#include "tcoding.h" #include "tcoding.h"
#include "tdlist.h" #include "tlist.h"
#include "tlockfree.h" #include "tlockfree.h"
#include "tmacro.h" #include "tmacro.h"
#include "wal.h" #include "wal.h"
......
...@@ -13,19 +13,20 @@ ...@@ -13,19 +13,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef _TD_COMMON_INT_H_ #ifndef _TD_VNODE_MAF_H_
#define _TD_COMMON_INT_H_ #define _TD_VNODE_MAF_H_
#include "vnode.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
extern bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags); int vnodeOpenMAF(SVnode *pVnode);
void vnodeCloseMAF(SVnode *pVnode);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /*_TD_COMMON_INT_H_*/ #endif /*_TD_VNODE_MAF_H_*/
\ No newline at end of file
...@@ -21,9 +21,9 @@ extern "C" { ...@@ -21,9 +21,9 @@ extern "C" {
#endif #endif
typedef struct { typedef struct {
uint64_t processed; int64_t processed;
uint64_t committed; int64_t committed;
uint64_t applied; int64_t applied;
} SVState; } SVState;
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -27,7 +27,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) { ...@@ -27,7 +27,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) {
pVMA->capacity = capacity; pVMA->capacity = capacity;
pVMA->ssize = ssize; pVMA->ssize = ssize;
pVMA->lsize = lsize; pVMA->lsize = lsize;
tSListInit(&(pVMA->nlist)); TD_SLIST_INIT(&(pVMA->nlist));
pVMA->pNode = vArenaNodeNew(capacity); pVMA->pNode = vArenaNodeNew(capacity);
if (pVMA->pNode == NULL) { if (pVMA->pNode == NULL) {
...@@ -35,7 +35,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) { ...@@ -35,7 +35,7 @@ SVMemAllocator *vmaCreate(uint64_t capacity, uint64_t ssize, uint64_t lsize) {
return NULL; return NULL;
} }
tSListPush(&(pVMA->nlist), pVMA->pNode); TD_SLIST_PUSH(&(pVMA->nlist), pVMA->pNode);
return pVMA; return pVMA;
} }
...@@ -44,7 +44,7 @@ void vmaDestroy(SVMemAllocator *pVMA) { ...@@ -44,7 +44,7 @@ void vmaDestroy(SVMemAllocator *pVMA) {
if (pVMA) { if (pVMA) {
while (TD_SLIST_NELES(&(pVMA->nlist)) > 1) { while (TD_SLIST_NELES(&(pVMA->nlist)) > 1) {
SVArenaNode *pNode = TD_SLIST_HEAD(&(pVMA->nlist)); SVArenaNode *pNode = TD_SLIST_HEAD(&(pVMA->nlist));
tSListPop(&(pVMA->nlist)); TD_SLIST_POP(&(pVMA->nlist));
vArenaNodeFree(pNode); vArenaNodeFree(pNode);
} }
...@@ -55,7 +55,7 @@ void vmaDestroy(SVMemAllocator *pVMA) { ...@@ -55,7 +55,7 @@ void vmaDestroy(SVMemAllocator *pVMA) {
void vmaReset(SVMemAllocator *pVMA) { void vmaReset(SVMemAllocator *pVMA) {
while (TD_SLIST_NELES(&(pVMA->nlist)) > 1) { while (TD_SLIST_NELES(&(pVMA->nlist)) > 1) {
SVArenaNode *pNode = TD_SLIST_HEAD(&(pVMA->nlist)); SVArenaNode *pNode = TD_SLIST_HEAD(&(pVMA->nlist));
tSListPop(&(pVMA->nlist)); TD_SLIST_POP(&(pVMA->nlist));
vArenaNodeFree(pNode); vArenaNodeFree(pNode);
} }
...@@ -75,7 +75,7 @@ void *vmaMalloc(SVMemAllocator *pVMA, uint64_t size) { ...@@ -75,7 +75,7 @@ void *vmaMalloc(SVMemAllocator *pVMA, uint64_t size) {
return NULL; return NULL;
} }
tSListPush(&(pVMA->nlist), pNode); TD_SLIST_PUSH(&(pVMA->nlist), pNode);
} }
ptr = pNode->ptr; ptr = pNode->ptr;
......
...@@ -24,10 +24,13 @@ struct SVBufPool { ...@@ -24,10 +24,13 @@ struct SVBufPool {
TD_DLIST(SVMemAllocator) free; TD_DLIST(SVMemAllocator) free;
TD_DLIST(SVMemAllocator) incycle; TD_DLIST(SVMemAllocator) incycle;
SVMemAllocator *inuse; SVMemAllocator *inuse;
// MAF for submodules // MAF for submodules to use
// SMemAllocatorFactory maf; SMemAllocatorFactory *pMAF;
}; };
static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pMAF);
static void vBufPoolDestroyMA(SMemAllocatorFactory *pMAF, SMemAllocator *pMA);
int vnodeOpenBufPool(SVnode *pVnode) { int vnodeOpenBufPool(SVnode *pVnode) {
uint64_t capacity; uint64_t capacity;
...@@ -36,8 +39,8 @@ int vnodeOpenBufPool(SVnode *pVnode) { ...@@ -36,8 +39,8 @@ int vnodeOpenBufPool(SVnode *pVnode) {
return -1; return -1;
} }
tDListInit(&(pVnode->pBufPool->free)); TD_DLIST_INIT(&(pVnode->pBufPool->free));
tDListInit(&(pVnode->pBufPool->incycle)); TD_DLIST_INIT(&(pVnode->pBufPool->incycle));
pVnode->pBufPool->inuse = NULL; pVnode->pBufPool->inuse = NULL;
...@@ -51,8 +54,17 @@ int vnodeOpenBufPool(SVnode *pVnode) { ...@@ -51,8 +54,17 @@ int vnodeOpenBufPool(SVnode *pVnode) {
return -1; return -1;
} }
tDListAppend(&(pVnode->pBufPool->free), pVMA); TD_DLIST_APPEND(&(pVnode->pBufPool->free), pVMA);
}
pVnode->pBufPool->pMAF = (SMemAllocatorFactory *)malloc(sizeof(SMemAllocatorFactory));
if (pVnode->pBufPool->pMAF == NULL) {
// TODO: handle error
return -1;
} }
pVnode->pBufPool->pMAF->impl = pVnode;
pVnode->pBufPool->pMAF->create = vBufPoolCreateMA;
pVnode->pBufPool->pMAF->destroy = vBufPoolDestroyMA;
return 0; return 0;
} }
...@@ -64,14 +76,14 @@ void vnodeCloseBufPool(SVnode *pVnode) { ...@@ -64,14 +76,14 @@ void vnodeCloseBufPool(SVnode *pVnode) {
while (true) { while (true) {
SVMemAllocator *pVMA = TD_DLIST_HEAD(&(pVnode->pBufPool->incycle)); SVMemAllocator *pVMA = TD_DLIST_HEAD(&(pVnode->pBufPool->incycle));
if (pVMA == NULL) break; if (pVMA == NULL) break;
tDListPop(&(pVnode->pBufPool->incycle), pVMA); TD_DLIST_POP(&(pVnode->pBufPool->incycle), pVMA);
vmaDestroy(pVMA); vmaDestroy(pVMA);
} }
while (true) { while (true) {
SVMemAllocator *pVMA = TD_DLIST_HEAD(&(pVnode->pBufPool->free)); SVMemAllocator *pVMA = TD_DLIST_HEAD(&(pVnode->pBufPool->free));
if (pVMA == NULL) break; if (pVMA == NULL) break;
tDListPop(&(pVnode->pBufPool->free), pVMA); TD_DLIST_POP(&(pVnode->pBufPool->free), pVMA);
vmaDestroy(pVMA); vmaDestroy(pVMA);
} }
...@@ -85,7 +97,7 @@ int vnodeBufPoolSwitch(SVnode *pVnode) { ...@@ -85,7 +97,7 @@ int vnodeBufPoolSwitch(SVnode *pVnode) {
pVnode->pBufPool->inuse = NULL; pVnode->pBufPool->inuse = NULL;
tDListAppend(&(pVnode->pBufPool->incycle), pvma); TD_DLIST_APPEND(&(pVnode->pBufPool->incycle), pvma);
return 0; return 0;
} }
...@@ -94,9 +106,9 @@ int vnodeBufPoolRecycle(SVnode *pVnode) { ...@@ -94,9 +106,9 @@ int vnodeBufPoolRecycle(SVnode *pVnode) {
SVMemAllocator *pvma = TD_DLIST_HEAD(&(pBufPool->incycle)); SVMemAllocator *pvma = TD_DLIST_HEAD(&(pBufPool->incycle));
ASSERT(pvma != NULL); ASSERT(pvma != NULL);
tDListPop(&(pBufPool->incycle), pvma); TD_DLIST_POP(&(pBufPool->incycle), pvma);
vmaReset(pvma); vmaReset(pvma);
tDListAppend(&(pBufPool->free), pvma); TD_DLIST_APPEND(&(pBufPool->free), pvma);
return 0; return 0;
} }
...@@ -109,7 +121,7 @@ void *vnodeMalloc(SVnode *pVnode, uint64_t size) { ...@@ -109,7 +121,7 @@ void *vnodeMalloc(SVnode *pVnode, uint64_t size) {
// TODO: add sem_wait and sem_post // TODO: add sem_wait and sem_post
pBufPool->inuse = TD_DLIST_HEAD(&(pBufPool->free)); pBufPool->inuse = TD_DLIST_HEAD(&(pBufPool->free));
if (pBufPool->inuse) { if (pBufPool->inuse) {
tDListPop(&(pBufPool->free), pBufPool->inuse); TD_DLIST_POP(&(pBufPool->free), pBufPool->inuse);
break; break;
} else { } else {
// tsem_wait(&(pBufPool->hasFree)); // tsem_wait(&(pBufPool->hasFree));
...@@ -125,195 +137,50 @@ bool vnodeBufPoolIsFull(SVnode *pVnode) { ...@@ -125,195 +137,50 @@ bool vnodeBufPoolIsFull(SVnode *pVnode) {
return vmaIsFull(pVnode->pBufPool->inuse); return vmaIsFull(pVnode->pBufPool->inuse);
} }
#if 0 SMemAllocatorFactory *vBufPoolGetMAF(SVnode *pVnode) { return pVnode->pBufPool->pMAF; }
typedef enum {
// Heap allocator
E_V_HEAP_ALLOCATOR = 0,
// Arena allocator
E_V_ARENA_ALLOCATOR
} EVMemAllocatorT;
typedef struct {
/* TODO */
} SVHeapAllocator;
typedef struct SVArenaNode {
struct SVArenaNode *prev;
uint64_t size;
void * ptr;
char data[];
} SVArenaNode;
typedef struct {
uint64_t ssize; // step size
uint64_t lsize; // limit size
SVArenaNode *inuse;
SVArenaNode node;
} SVArenaAllocator;
/* ------------------------ STATIC METHODS ------------------------ */
typedef struct { typedef struct {
SVnode * pVnode; SVnode * pVnode;
SListNode *pNode; SVMemAllocator *pVMA;
} SVMAWrapper; } SVMAWrapper;
static FORCE_INLINE void *vmaMaloocCb(SMemAllocator *pMA, uint64_t size) {
SVMAWrapper *pWrapper = (SVMAWrapper *)(pMA->impl);
static SListNode * vBufPoolNewNode(uint64_t capacity, EVMemAllocatorT type); return vmaMalloc(pWrapper->pVMA, size);
static void vBufPoolFreeNode(SListNode *pNode);
static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pmaf);
static void vBufPoolDestroyMA(SMemAllocatorFactory *pmaf, SMemAllocator *pma);
static void * vBufPoolMalloc(SVMemAllocator *pvma, uint64_t size);
/* ------------------------ STATIC METHODS ------------------------ */
static SListNode *vBufPoolNewNode(uint64_t capacity, EVMemAllocatorT type) {
SListNode * pNode;
SVMemAllocator *pvma;
uint64_t msize;
uint64_t ssize = 4096; // TODO
uint64_t lsize = 1024; // TODO
msize = sizeof(SListNode) + sizeof(SVMemAllocator);
if (type == E_V_ARENA_ALLOCATOR) {
msize += capacity;
}
pNode = (SListNode *)calloc(1, msize);
if (pNode == NULL) {
// TODO: handle error
return NULL;
}
pvma = (SVMemAllocator *)(pNode->data);
pvma->capacity = capacity;
pvma->type = type;
switch (type) {
case E_V_ARENA_ALLOCATOR:
vArenaAllocatorInit(&(pvma->vaa), capacity, ssize, lsize);
break;
case E_V_HEAP_ALLOCATOR:
// vHeapAllocatorInit(&(pvma->vha));
break;
default:
ASSERT(0);
}
return pNode;
} }
static void vBufPoolFreeNode(SListNode *pNode) { // TODO: Add atomic operations here
SVMemAllocator *pvma = (SVMemAllocator *)(pNode->data); static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pMAF) {
SMemAllocator *pMA;
SVnode * pVnode = (SVnode *)(pMAF->impl);
SVMAWrapper * pWrapper;
switch (pvma->type) { pMA = (SMemAllocator *)calloc(1, sizeof(*pMA) + sizeof(SVMAWrapper));
case E_V_ARENA_ALLOCATOR: if (pMA == NULL) {
vArenaAllocatorClear(&(pvma->vaa));
break;
case E_V_HEAP_ALLOCATOR:
// vHeapAllocatorClear(&(pvma->vha));
break;
default:
break;
}
free(pNode);
}
static void *vBufPoolMalloc(SVMemAllocator *pvma, uint64_t size) {
void *ptr = NULL;
if (pvma->type == E_V_ARENA_ALLOCATOR) {
SVArenaAllocator *pvaa = &(pvma->vaa);
if (POINTER_DISTANCE(pvaa->inuse->ptr, pvaa->inuse->data) + size > pvaa->inuse->size) {
SVArenaNode *pNode = (SVArenaNode *)malloc(sizeof(*pNode) + MAX(size, pvaa->ssize));
if (pNode == NULL) {
// TODO: handle error
return NULL; return NULL;
} }
pNode->prev = pvaa->inuse; pVnode->pBufPool->inuse->_ref.val++;
pNode->size = MAX(size, pvaa->ssize); pWrapper = POINTER_SHIFT(pMA, sizeof(*pMA));
pNode->ptr = pNode->data; pWrapper->pVnode = pVnode;
pWrapper->pVMA = pVnode->pBufPool->inuse;
pvaa->inuse = pNode; pMA->impl = pWrapper;
} TD_MA_MALLOC_FUNC(pMA) = vmaMaloocCb;
ptr = pvaa->inuse->ptr; return pMA;
pvaa->inuse->ptr = POINTER_SHIFT(ptr, size);
} else if (pvma->type == E_V_HEAP_ALLOCATOR) {
/* TODO */
}
return ptr;
} }
static SMemAllocator *vBufPoolCreateMA(SMemAllocatorFactory *pmaf) { static void vBufPoolDestroyMA(SMemAllocatorFactory *pMAF, SMemAllocator *pMA) {
SVnode * pVnode; SVMAWrapper * pWrapper = (SVMAWrapper *)(pMA->impl);
SMemAllocator * pma; SVnode * pVnode = pWrapper->pVnode;
SVMemAllocator *pvma; SVMemAllocator *pVMA = pWrapper->pVMA;
SVMAWrapper * pvmaw;
pVnode = (SVnode *)(pmaf->impl);
pma = (SMemAllocator *)calloc(1, sizeof(*pma) + sizeof(SVMAWrapper));
if (pma == NULL) {
// TODO: handle error
return NULL;
}
pvmaw = (SVMAWrapper *)POINTER_SHIFT(pma, sizeof(*pma));
// No allocator used currently
if (pVnode->pBufPool->inuse == NULL) {
while (listNEles(&(pVnode->pBufPool->free)) == 0) {
// TODO: wait until all released ro kill query
// tsem_wait();
ASSERT(0);
}
pVnode->pBufPool->inuse = tdListPopHead(&(pVnode->pBufPool->free));
pvma = (SVMemAllocator *)(pVnode->pBufPool->inuse->data);
T_REF_INIT_VAL(pvma, 1);
} else {
pvma = (SVMemAllocator *)(pVnode->pBufPool->inuse->data);
}
T_REF_INC(pvma);
pvmaw->pVnode = pVnode;
pvmaw->pNode = pVnode->pBufPool->inuse;
pma->impl = pvmaw;
pma->malloc = NULL;
pma->calloc = NULL; /* TODO */
pma->realloc = NULL; /* TODO */
pma->free = NULL; /* TODO */
pma->usage = NULL; /* TODO */
return pma;
}
static void vBufPoolDestroyMA(SMemAllocatorFactory *pmaf, SMemAllocator *pma) { /* TODO */
SVnode * pVnode = (SVnode *)(pmaf->impl);
SListNode * pNode = ((SVMAWrapper *)(pma->impl))->pNode;
SVMemAllocator *pvma = (SVMemAllocator *)(pNode->data);
if (T_REF_DEC(pvma) == 0) {
if (pvma->type == E_V_ARENA_ALLOCATOR) {
SVArenaAllocator *pvaa = &(pvma->vaa);
while (pvaa->inuse != &(pvaa->node)) {
SVArenaNode *pNode = pvaa->inuse;
pvaa->inuse = pNode->prev;
/* code */
}
pvaa->inuse->ptr = pvaa->inuse->data;
} else if (pvma->type == E_V_HEAP_ALLOCATOR) {
} else {
ASSERT(0);
}
// Move node from incycle to free free(pMA);
tdListAppendNode(&(pVnode->pBufPool->free), tdListPopNode(&(pVnode->pBufPool->incycle), pNode)); if (--pVMA->_ref.val == 0) {
// tsem_post(); todo: sem_post TD_DLIST_POP(&(pVnode->pBufPool->incycle), pVMA);
TD_DLIST_APPEND(&(pVnode->pBufPool->free), pVMA);
} }
} }
\ No newline at end of file
#endif
\ No newline at end of file
...@@ -94,7 +94,7 @@ static int vnodeOpenImpl(SVnode *pVnode) { ...@@ -94,7 +94,7 @@ static int vnodeOpenImpl(SVnode *pVnode) {
// Open meta // Open meta
sprintf(dir, "%s/meta", pVnode->path); sprintf(dir, "%s/meta", pVnode->path);
pVnode->pMeta = metaOpen(dir, &(pVnode->config.metaCfg)); pVnode->pMeta = metaOpen(dir, &(pVnode->config.metaCfg), vBufPoolGetMAF(pVnode));
if (pVnode->pMeta == NULL) { if (pVnode->pMeta == NULL) {
// TODO: handle error // TODO: handle error
return -1; return -1;
...@@ -102,7 +102,7 @@ static int vnodeOpenImpl(SVnode *pVnode) { ...@@ -102,7 +102,7 @@ static int vnodeOpenImpl(SVnode *pVnode) {
// Open tsdb // Open tsdb
sprintf(dir, "%s/tsdb", pVnode->path); sprintf(dir, "%s/tsdb", pVnode->path);
pVnode->pTsdb = tsdbOpen(dir, &(pVnode->config.tsdbCfg)); pVnode->pTsdb = tsdbOpen(dir, &(pVnode->config.tsdbCfg), vBufPoolGetMAF(pVnode));
if (pVnode->pTsdb == NULL) { if (pVnode->pTsdb == NULL) {
// TODO: handle error // TODO: handle error
return -1; return -1;
...@@ -110,7 +110,7 @@ static int vnodeOpenImpl(SVnode *pVnode) { ...@@ -110,7 +110,7 @@ static int vnodeOpenImpl(SVnode *pVnode) {
// TODO: Open TQ // TODO: Open TQ
sprintf(dir, "%s/tq", pVnode->path); sprintf(dir, "%s/tq", pVnode->path);
pVnode->pTq = tqOpen(dir, &(pVnode->config.tqCfg), NULL, NULL); pVnode->pTq = tqOpen(dir, &(pVnode->config.tqCfg), NULL, vBufPoolGetMAF(pVnode));
if (pVnode->pTq == NULL) { if (pVnode->pTq == NULL) {
// TODO: handle error // TODO: handle error
return -1; return -1;
...@@ -131,7 +131,9 @@ static int vnodeOpenImpl(SVnode *pVnode) { ...@@ -131,7 +131,9 @@ static int vnodeOpenImpl(SVnode *pVnode) {
static void vnodeCloseImpl(SVnode *pVnode) { static void vnodeCloseImpl(SVnode *pVnode) {
if (pVnode) { if (pVnode) {
vnodeCloseBufPool(pVnode); vnodeCloseBufPool(pVnode);
tsdbClose(pVnode->pTsdb);
metaClose(pVnode->pMeta); metaClose(pVnode->pMeta);
tsdbClose(pVnode->pTsdb);
tqClose(pVnode->pTq);
walClose(pVnode->pWal);
} }
} }
\ No newline at end of file
...@@ -34,7 +34,7 @@ int vnodeInit(uint16_t nthreads) { ...@@ -34,7 +34,7 @@ int vnodeInit(uint16_t nthreads) {
pthread_mutex_init(&(vnodeMgr.mutex), NULL); pthread_mutex_init(&(vnodeMgr.mutex), NULL);
pthread_cond_init(&(vnodeMgr.hasTask), NULL); pthread_cond_init(&(vnodeMgr.hasTask), NULL);
tDListInit(&(vnodeMgr.queue)); TD_DLIST_INIT(&(vnodeMgr.queue));
for (uint16_t i = 0; i < nthreads; i++) { for (uint16_t i = 0; i < nthreads; i++) {
pthread_create(&(vnodeMgr.threads[i]), NULL, loop, NULL); pthread_create(&(vnodeMgr.threads[i]), NULL, loop, NULL);
...@@ -77,7 +77,7 @@ void vnodeClear() { ...@@ -77,7 +77,7 @@ void vnodeClear() {
int vnodeScheduleTask(SVnodeTask* pTask) { int vnodeScheduleTask(SVnodeTask* pTask) {
pthread_mutex_lock(&(vnodeMgr.mutex)); pthread_mutex_lock(&(vnodeMgr.mutex));
tDListAppend(&(vnodeMgr.queue), pTask); TD_DLIST_APPEND(&(vnodeMgr.queue), pTask);
pthread_cond_signal(&(vnodeMgr.hasTask)); pthread_cond_signal(&(vnodeMgr.hasTask));
...@@ -101,7 +101,7 @@ static void* loop(void* arg) { ...@@ -101,7 +101,7 @@ static void* loop(void* arg) {
pthread_cond_wait(&(vnodeMgr.hasTask), &(vnodeMgr.mutex)); pthread_cond_wait(&(vnodeMgr.hasTask), &(vnodeMgr.mutex));
} }
} else { } else {
tDListPop(&(vnodeMgr.queue), pTask); TD_DLIST_POP(&(vnodeMgr.queue), pTask);
break; break;
} }
} }
......
...@@ -25,9 +25,10 @@ int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type) { ...@@ -25,9 +25,10 @@ int vnodeBuildReq(void **buf, const SVnodeReq *pReq, uint8_t type) {
switch (type) { switch (type) {
case TSDB_MSG_TYPE_CREATE_TABLE: case TSDB_MSG_TYPE_CREATE_TABLE:
tsize += vnodeBuildCreateTableReq(buf, &(pReq->ctReq)); tsize += vnodeBuildCreateTableReq(buf, &(pReq->ctReq));
break;
case TSDB_MSG_TYPE_SUBMIT:
/* code */ /* code */
break; break;
default: default:
break; break;
} }
......
...@@ -15,16 +15,31 @@ ...@@ -15,16 +15,31 @@
#include "vnodeDef.h" #include "vnodeDef.h"
int vnodeProcessNoWalWMsgs(SVnode *pVnode, SRpcMsg *pMsg) {
SVnodeReq *pVnodeReq;
switch (pMsg->msgType) {
case TSDB_MSG_TYPE_MQ_SET:
if (tqSetCursor(pVnode->pTq, pMsg->pCont) < 0) {
// TODO: handle error
}
break;
}
void *pBuf = pMsg->pCont;
return 0;
}
int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) { int vnodeProcessWMsgs(SVnode *pVnode, SArray *pMsgs) {
SRpcMsg * pMsg; SRpcMsg *pMsg;
SVnodeReq *pVnodeReq; SVnodeReq *pVnodeReq;
for (int i = 0; i < taosArrayGetSize(pMsgs); i++) { for (int i = 0; i < taosArrayGetSize(pMsgs); i++) {
pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i); pMsg = *(SRpcMsg **)taosArrayGet(pMsgs, i);
// ser request version // ser request version
void * pBuf = pMsg->pCont; void *pBuf = pMsg->pCont;
uint64_t ver = pVnode->state.processed++; int64_t ver = pVnode->state.processed++;
taosEncodeFixedU64(&pBuf, ver); taosEncodeFixedU64(&pBuf, ver);
if (walWrite(pVnode->pWal, ver, pMsg->msgType, pMsg->pCont, pMsg->contLen) < 0) { if (walWrite(pVnode->pWal, ver, pMsg->msgType, pMsg->pCont, pMsg->contLen) < 0) {
......
// https://stackoverflow.com/questions/8565666/benchmarking-with-googletest
// https://github.com/google/benchmark
\ No newline at end of file
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "vnode.h" #include "vnode.h"
static STSchema *createBasicSchema() { static STSchema *vtCreateBasicSchema() {
STSchemaBuilder sb; STSchemaBuilder sb;
STSchema * pSchema = NULL; STSchema * pSchema = NULL;
...@@ -32,7 +32,7 @@ static STSchema *createBasicSchema() { ...@@ -32,7 +32,7 @@ static STSchema *createBasicSchema() {
return pSchema; return pSchema;
} }
static STSchema *createBasicTagSchema() { static STSchema *vtCreateBasicTagSchema() {
STSchemaBuilder sb; STSchemaBuilder sb;
STSchema * pSchema = NULL; STSchema * pSchema = NULL;
...@@ -50,7 +50,7 @@ static STSchema *createBasicTagSchema() { ...@@ -50,7 +50,7 @@ static STSchema *createBasicTagSchema() {
return pSchema; return pSchema;
} }
static SKVRow createBasicTag() { static SKVRow vtCreateBasicTag() {
SKVRowBuilder rb; SKVRowBuilder rb;
SKVRow pTag; SKVRow pTag;
...@@ -71,80 +71,43 @@ static SKVRow createBasicTag() { ...@@ -71,80 +71,43 @@ static SKVRow createBasicTag() {
return pTag; return pTag;
} }
#if 0 static void vtBuildCreateStbReq(tb_uid_t suid, char *tbname, SRpcMsg **ppMsg) {
TEST(vnodeApiTest, test_create_table_encode_and_decode_function) { SRpcMsg * pMsg;
tb_uid_t suid = 1638166374163; STSchema *pSchema;
STSchema *pSchema = createBasicSchema(); STSchema *pTagSchema;
STSchema *pTagSchema = createBasicTagSchema(); int zs;
char tbname[128] = "st"; void * pBuf;
char * buffer = new char[1024];
void * pBuf = (void *)buffer;
SVnodeReq vCreateSTbReq = VNODE_INIT_CREATE_STB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema);
vnodeBuildReq(&pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
SVnodeReq decoded_req;
vnodeParseReq(buffer, &decoded_req, TSDB_MSG_TYPE_CREATE_TABLE);
int k = 10;
}
#endif
TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) {
vnodeDestroy("vnode1");
GTEST_ASSERT_GE(vnodeInit(2), 0); pSchema = vtCreateBasicSchema();
pTagSchema = vtCreateBasicTagSchema();
// Create and open a vnode
SVnode *pVnode = vnodeOpen("vnode1", NULL);
ASSERT_NE(pVnode, nullptr);
tb_uid_t suid = 1638166374163;
{
// Create a super table
STSchema *pSchema = createBasicSchema();
STSchema *pTagSchema = createBasicTagSchema();
char tbname[128] = "st";
SArray * pMsgs = (SArray *)taosArrayInit(1, sizeof(SRpcMsg *));
SVnodeReq vCreateSTbReq = VNODE_INIT_CREATE_STB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema); SVnodeReq vCreateSTbReq = VNODE_INIT_CREATE_STB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pSchema, pTagSchema);
int zs = vnodeBuildReq(NULL, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE); zs = vnodeBuildReq(NULL, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + zs); pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + zs);
pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE; pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE;
pMsg->contLen = zs; pMsg->contLen = zs;
pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(SRpcMsg)); pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(SRpcMsg));
void *pBuf = pMsg->pCont; pBuf = pMsg->pCont;
vnodeBuildReq(&pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE); vnodeBuildReq(&pBuf, &vCreateSTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
META_CLEAR_TB_CFG(&vCreateSTbReq); META_CLEAR_TB_CFG(&vCreateSTbReq);
taosArrayPush(pMsgs, &(pMsg));
vnodeProcessWMsgs(pVnode, pMsgs);
free(pMsg);
taosArrayDestroy(pMsgs);
tdFreeSchema(pSchema); tdFreeSchema(pSchema);
tdFreeSchema(pTagSchema); tdFreeSchema(pTagSchema);
}
{ *ppMsg = pMsg;
// Create some child tables }
int ntables = 1000000;
int batch = 10; static void vtBuildCreateCtbReq(tb_uid_t suid, char *tbname, SRpcMsg **ppMsg) {
for (int i = 0; i < ntables / batch; i++) { SRpcMsg *pMsg;
SArray *pMsgs = (SArray *)taosArrayInit(batch, sizeof(SRpcMsg *)); int tz;
for (int j = 0; j < batch; j++) { SKVRow pTag = vtCreateBasicTag();
SKVRow pTag = createBasicTag();
char tbname[128];
sprintf(tbname, "tb%d", i * batch + j);
SVnodeReq vCreateCTbReq = VNODE_INIT_CREATE_CTB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pTag); SVnodeReq vCreateCTbReq = VNODE_INIT_CREATE_CTB_REQ(tbname, UINT32_MAX, UINT32_MAX, suid, pTag);
int tz = vnodeBuildReq(NULL, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE); tz = vnodeBuildReq(NULL, &vCreateCTbReq, TSDB_MSG_TYPE_CREATE_TABLE);
SRpcMsg *pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + tz); pMsg = (SRpcMsg *)malloc(sizeof(SRpcMsg) + tz);
pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE; pMsg->msgType = TSDB_MSG_TYPE_CREATE_TABLE;
pMsg->contLen = tz; pMsg->contLen = tz;
pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg)); pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg));
...@@ -154,35 +117,157 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) { ...@@ -154,35 +117,157 @@ TEST(vnodeApiTest, vnodeOpen_vnodeClose_test) {
META_CLEAR_TB_CFG(&vCreateCTbReq); META_CLEAR_TB_CFG(&vCreateCTbReq);
free(pTag); free(pTag);
taosArrayPush(pMsgs, &(pMsg)); *ppMsg = pMsg;
} }
vnodeProcessWMsgs(pVnode, pMsgs); static void vtBuildCreateNtbReq(char *tbname, SRpcMsg **ppMsg) {
// TODO
}
for (int j = 0; j < batch; j++) { static void vtBuildSubmitReq(SRpcMsg **ppMsg) {
SRpcMsg *pMsg = *(SRpcMsg **)taosArrayPop(pMsgs); SRpcMsg * pMsg;
SSubmitMsg *pSubmitMsg;
SSubmitBlk *pSubmitBlk;
int tz = 1024; // TODO
pMsg = (SRpcMsg *)malloc(sizeof(*pMsg) + tz);
pMsg->msgType = TSDB_MSG_TYPE_SUBMIT;
pMsg->contLen = tz;
pMsg->pCont = POINTER_SHIFT(pMsg, sizeof(*pMsg));
// For submit msg header
pSubmitMsg = (SSubmitMsg *)(pMsg->pCont);
// pSubmitMsg->header.contLen = 0;
// pSubmitMsg->header.vgId = 0;
// pSubmitMsg->length = 0;
pSubmitMsg->numOfBlocks = 1;
// For submit blk
pSubmitBlk = (SSubmitBlk *)(pSubmitMsg->blocks);
pSubmitBlk->uid = 0;
pSubmitBlk->tid = 0;
pSubmitBlk->padding = 0;
pSubmitBlk->sversion = 0;
pSubmitBlk->dataLen = 0;
pSubmitBlk->numOfRows = 0;
// For row batch
*ppMsg = pMsg;
}
static void vtClearMsgBatch(SArray *pMsgArr) {
SRpcMsg *pMsg;
for (size_t i = 0; i < taosArrayGetSize(pMsgArr); i++) {
pMsg = *(SRpcMsg **)taosArrayGet(pMsgArr, i);
free(pMsg); free(pMsg);
} }
taosArrayDestroy(pMsgs); taosArrayClear(pMsgArr);
}
TEST(vnodeApiTest, vnode_simple_create_table_test) {
tb_uid_t suid = 1638166374163;
SRpcMsg *pMsg;
SArray * pMsgArr = NULL;
SVnode * pVnode;
int rcode;
int ntables = 1000000;
int batch = 10;
char tbname[128];
pMsgArr = (SArray *)taosArrayInit(batch, sizeof(pMsg));
// std::cout << "the " << i << "th batch is created" << std::endl; vnodeDestroy("vnode1");
GTEST_ASSERT_GE(vnodeInit(2), 0);
// CREATE AND OPEN A VNODE
pVnode = vnodeOpen("vnode1", NULL);
ASSERT_NE(pVnode, nullptr);
// CREATE A SUPER TABLE
sprintf(tbname, "st");
vtBuildCreateStbReq(suid, tbname, &pMsg);
taosArrayPush(pMsgArr, &pMsg);
rcode = vnodeProcessWMsgs(pVnode, pMsgArr);
ASSERT_EQ(rcode, 0);
vtClearMsgBatch(pMsgArr);
// CREATE A LOT OF CHILD TABLES
for (int i = 0; i < ntables / batch; i++) {
// Build request batch
for (int j = 0; j < batch; j++) {
sprintf(tbname, "ct%d", i * batch + j + 1);
vtBuildCreateCtbReq(suid, tbname, &pMsg);
taosArrayPush(pMsgArr, &pMsg);
} }
// Process request batch
rcode = vnodeProcessWMsgs(pVnode, pMsgArr);
ASSERT_EQ(rcode, 0);
// Clear request batch
vtClearMsgBatch(pMsgArr);
} }
// Close the vnode // CLOSE THE VNODE
vnodeClose(pVnode); vnodeClose(pVnode);
vnodeClear(); vnodeClear();
taosArrayDestroy(pMsgArr);
} }
TEST(vnodeApiTest, DISABLED_vnode_process_create_table) { TEST(vnodeApiTest, vnode_simple_insert_test) {
STSchema * pSchema = NULL; const char *vname = "vnode2";
STSchema * pTagSchema = NULL; char tbname[128];
char stname[15]; tb_uid_t suid = 1638166374163;
SVCreateTableReq pReq = META_INIT_STB_CFG(stname, UINT32_MAX, UINT32_MAX, 0, pSchema, pTagSchema); SRpcMsg * pMsg;
SArray * pMsgArr;
int rcode;
SVnode * pVnode;
int batch = 1;
int loop = 1000000;
pMsgArr = (SArray *)taosArrayInit(0, sizeof(pMsg));
int k = 10; vnodeDestroy(vname);
GTEST_ASSERT_GE(vnodeInit(2), 0);
// Open a vnode
pVnode = vnodeOpen(vname, NULL);
GTEST_ASSERT_NE(pVnode, nullptr);
// 1. CREATE A SUPER TABLE
sprintf(tbname, "st");
vtBuildCreateStbReq(suid, tbname, &pMsg);
taosArrayPush(pMsgArr, &pMsg);
rcode = vnodeProcessWMsgs(pVnode, pMsgArr);
GTEST_ASSERT_EQ(rcode, 0);
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);
vtClearMsgBatch(pMsgArr);
// 3. WRITE A LOT OF TIME-SERIES DATA
for (int j = 0; j < loop; j++) {
for (int i = 0; i < batch; i++) {
vtBuildSubmitReq(&pMsg);
taosArrayPush(pMsgArr, &pMsg);
}
rcode = vnodeProcessWMsgs(pVnode, pMsgArr);
GTEST_ASSERT_EQ(rcode, 0);
vtClearMsgBatch(pMsgArr);
}
// Close the vnode
vnodeClose(pVnode);
vnodeClear();
META_CLEAR_TB_CFG(pReq); taosArrayDestroy(pMsgArr);
} }
\ No newline at end of file
...@@ -17,27 +17,27 @@ ...@@ -17,27 +17,27 @@
#include "metaDef.h" #include "metaDef.h"
static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions); static SMeta *metaNew(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF);
static void metaFree(SMeta *pMeta); static void metaFree(SMeta *pMeta);
static int metaOpenImpl(SMeta *pMeta); static int metaOpenImpl(SMeta *pMeta);
static void metaCloseImpl(SMeta *pMeta); static void metaCloseImpl(SMeta *pMeta);
SMeta *metaOpen(const char *path, const SMetaCfg *pMetaOptions) { SMeta *metaOpen(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF) {
SMeta *pMeta = NULL; SMeta *pMeta = NULL;
// Set default options // Set default options
if (pMetaOptions == NULL) { if (pMetaCfg == NULL) {
pMetaOptions = &defaultMetaOptions; pMetaCfg = &defaultMetaOptions;
} }
// Validate the options // Validate the options
if (metaValidateOptions(pMetaOptions) < 0) { if (metaValidateOptions(pMetaCfg) < 0) {
// TODO: deal with error // TODO: deal with error
return NULL; return NULL;
} }
// Allocate handle // Allocate handle
pMeta = metaNew(path, pMetaOptions); pMeta = metaNew(path, pMetaCfg, pMAF);
if (pMeta == NULL) { if (pMeta == NULL) {
// TODO: handle error // TODO: handle error
return NULL; return NULL;
...@@ -65,7 +65,7 @@ void metaClose(SMeta *pMeta) { ...@@ -65,7 +65,7 @@ void metaClose(SMeta *pMeta) {
void metaRemove(const char *path) { taosRemoveDir(path); } void metaRemove(const char *path) { taosRemoveDir(path); }
/* ------------------------ STATIC METHODS ------------------------ */ /* ------------------------ STATIC METHODS ------------------------ */
static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions) { static SMeta *metaNew(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF) {
SMeta *pMeta; SMeta *pMeta;
size_t psize = strlen(path); size_t psize = strlen(path);
...@@ -80,7 +80,8 @@ static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions) { ...@@ -80,7 +80,8 @@ static SMeta *metaNew(const char *path, const SMetaCfg *pMetaOptions) {
return NULL; return NULL;
} }
metaOptionsCopy(&(pMeta->options), pMetaOptions); metaOptionsCopy(&(pMeta->options), pMetaCfg);
pMeta->pmaf = pMAF;
return pMeta; return pMeta;
}; };
......
...@@ -22,16 +22,16 @@ ...@@ -22,16 +22,16 @@
extern "C" { extern "C" {
#endif #endif
//create persistent storage for meta info such as consuming offset // create persistent storage for meta info such as consuming offset
//return value > 0: cgId // return value > 0: cgId
//return value <= 0: error code // return value <= 0: error code
//int tqCreateTCGroup(STQ*, const char* topic, int cgId, tqBufferHandle** handle); // int tqCreateTCGroup(STQ*, const char* topic, int cgId, tqBufferHandle** handle);
//create ring buffer in memory and load consuming offset // create ring buffer in memory and load consuming offset
//int tqOpenTCGroup(STQ*, const char* topic, int cgId); // int tqOpenTCGroup(STQ*, const char* topic, int cgId);
//destroy ring buffer and persist consuming offset // destroy ring buffer and persist consuming offset
//int tqCloseTCGroup(STQ*, const char* topic, int cgId); // int tqCloseTCGroup(STQ*, const char* topic, int cgId);
//delete persistent storage for meta info // delete persistent storage for meta info
//int tqDropTCGroup(STQ*, const char* topic, int cgId); // int tqDropTCGroup(STQ*, const char* topic, int cgId);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -23,27 +23,22 @@ ...@@ -23,27 +23,22 @@
extern "C" { extern "C" {
#endif #endif
STqMetaStore* tqStoreOpen(const char* path, FTqSerialize pSerializer, FTqDeserialize pDeserializer, FTqDelete pDeleter,
STqMetaStore* tqStoreOpen(const char* path, int32_t tqConfigFlag);
FTqSerialize pSerializer,
FTqDeserialize pDeserializer,
FTqDelete pDeleter,
int32_t tqConfigFlag
);
int32_t tqStoreClose(STqMetaStore*); int32_t tqStoreClose(STqMetaStore*);
//int32_t tqStoreDelete(TqMetaStore*); // int32_t tqStoreDelete(TqMetaStore*);
//int32_t tqStoreCommitAll(TqMetaStore*); // int32_t tqStoreCommitAll(TqMetaStore*);
int32_t tqStorePersist(STqMetaStore*); int32_t tqStorePersist(STqMetaStore*);
//clean deleted idx and data from persistent file // clean deleted idx and data from persistent file
int32_t tqStoreCompact(STqMetaStore*); int32_t tqStoreCompact(STqMetaStore*);
void* tqHandleGet(STqMetaStore*, int64_t key); void* tqHandleGet(STqMetaStore*, int64_t key);
//make it unpersist // make it unpersist
void* tqHandleTouchGet(STqMetaStore*, int64_t key); void* tqHandleTouchGet(STqMetaStore*, int64_t key);
int32_t tqHandleMovePut(STqMetaStore*, int64_t key, void* value); int32_t tqHandleMovePut(STqMetaStore*, int64_t key, void* value);
int32_t tqHandleCopyPut(STqMetaStore*, int64_t key, void* value, size_t vsize); int32_t tqHandleCopyPut(STqMetaStore*, int64_t key, void* value, size_t vsize);
//delete committed kv pair // delete committed kv pair
//notice that a delete action still needs to be committed // notice that a delete action still needs to be committed
int32_t tqHandleDel(STqMetaStore*, int64_t key); int32_t tqHandleDel(STqMetaStore*, int64_t key);
int32_t tqHandleCommit(STqMetaStore*, int64_t key); int32_t tqHandleCommit(STqMetaStore*, int64_t key);
int32_t tqHandleAbort(STqMetaStore*, int64_t key); int32_t tqHandleAbort(STqMetaStore*, int64_t key);
......
...@@ -63,7 +63,13 @@ STQ* tqOpen(const char* path, STqCfg* tqConfig, STqLogReader* tqLogReader, SMemA ...@@ -63,7 +63,13 @@ STQ* tqOpen(const char* path, STqCfg* tqConfig, STqLogReader* tqLogReader, SMemA
return pTq; return pTq;
} }
static int tqProtoCheck(TmqMsgHead* pMsg) { return pMsg->protoVer == 0; } void tqClose(STQ*pTq) {
// TODO
}
static int tqProtoCheck(TmqMsgHead *pMsg) {
return pMsg->protoVer == 0;
}
static int tqAckOneTopic(STqBufferHandle* bHandle, TmqOneAck* pAck, STqQueryMsg** ppQuery) { static int tqAckOneTopic(STqBufferHandle* bHandle, TmqOneAck* pAck, STqQueryMsg** ppQuery) {
// clean old item and move forward // clean old item and move forward
...@@ -214,7 +220,11 @@ int tqCommit(STQ* pTq) { ...@@ -214,7 +220,11 @@ int tqCommit(STQ* pTq) {
return 0; return 0;
} }
int tqConsume(STQ* pTq, TmqConsumeReq* pMsg) { int tqSetCursor(STQ* pTq, void* msg) {
return 0;
}
int tqConsume(STQ* pTq, STqConsumeReq* pMsg) {
if (!tqProtoCheck((TmqMsgHead*)pMsg)) { if (!tqProtoCheck((TmqMsgHead*)pMsg)) {
// proto version invalid // proto version invalid
return -1; return -1;
...@@ -232,7 +242,7 @@ int tqConsume(STQ* pTq, TmqConsumeReq* pMsg) { ...@@ -232,7 +242,7 @@ int tqConsume(STQ* pTq, TmqConsumeReq* pMsg) {
} }
} }
TmqConsumeRsp* pRsp = (TmqConsumeRsp*)pMsg; STqConsumeRsp* pRsp = (STqConsumeRsp*)pMsg;
if (tqFetch(gHandle, (void**)&pRsp->msgs) <= 0) { if (tqFetch(gHandle, (void**)&pRsp->msgs) <= 0) {
// fetch error // fetch error
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "mallocator.h" #include "mallocator.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tdlist.h" #include "tlist.h"
#include "thash.h" #include "thash.h"
#include "tskiplist.h" #include "tskiplist.h"
......
...@@ -15,27 +15,27 @@ ...@@ -15,27 +15,27 @@
#include "tsdbDef.h" #include "tsdbDef.h"
static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions); static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF);
static void tsdbFree(STsdb *pTsdb); static void tsdbFree(STsdb *pTsdb);
static int tsdbOpenImpl(STsdb *pTsdb); static int tsdbOpenImpl(STsdb *pTsdb);
static void tsdbCloseImpl(STsdb *pTsdb); static void tsdbCloseImpl(STsdb *pTsdb);
STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbOptions) { STsdb *tsdbOpen(const char *path, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF) {
STsdb *pTsdb = NULL; STsdb *pTsdb = NULL;
// Set default TSDB Options // Set default TSDB Options
if (pTsdbOptions == NULL) { if (pTsdbCfg == NULL) {
pTsdbOptions = &defautlTsdbOptions; pTsdbCfg = &defautlTsdbOptions;
} }
// Validate the options // Validate the options
if (tsdbValidateOptions(pTsdbOptions) < 0) { if (tsdbValidateOptions(pTsdbCfg) < 0) {
// TODO: handle error // TODO: handle error
return NULL; return NULL;
} }
// Create the handle // Create the handle
pTsdb = tsdbNew(path, pTsdbOptions); pTsdb = tsdbNew(path, pTsdbCfg, pMAF);
if (pTsdb == NULL) { if (pTsdb == NULL) {
// TODO: handle error // TODO: handle error
return NULL; return NULL;
...@@ -62,7 +62,7 @@ void tsdbClose(STsdb *pTsdb) { ...@@ -62,7 +62,7 @@ void tsdbClose(STsdb *pTsdb) {
void tsdbRemove(const char *path) { taosRemoveDir(path); } void tsdbRemove(const char *path) { taosRemoveDir(path); }
/* ------------------------ STATIC METHODS ------------------------ */ /* ------------------------ STATIC METHODS ------------------------ */
static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions) { static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF) {
STsdb *pTsdb = NULL; STsdb *pTsdb = NULL;
pTsdb = (STsdb *)calloc(1, sizeof(STsdb)); pTsdb = (STsdb *)calloc(1, sizeof(STsdb));
...@@ -72,7 +72,8 @@ static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions) { ...@@ -72,7 +72,8 @@ static STsdb *tsdbNew(const char *path, const STsdbCfg *pTsdbOptions) {
} }
pTsdb->path = strdup(path); pTsdb->path = strdup(path);
tsdbOptionsCopy(&(pTsdb->options), pTsdbOptions); tsdbOptionsCopy(&(pTsdb->options), pTsdbCfg);
pTsdb->pmaf = pMAF;
return pTsdb; return pTsdb;
} }
......
...@@ -50,7 +50,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) { ...@@ -50,7 +50,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) {
pMA = (*pMAF->create)(pMAF); pMA = (*pMAF->create)(pMAF);
ASSERT(pMA != NULL); ASSERT(pMA != NULL);
pMemTable = (STsdbMemTable *)((*pMA->malloc)(pMA, sizeof(*pMemTable))); pMemTable = (STsdbMemTable *)TD_MA_MALLOC(pMA, sizeof(*pMemTable));
if (pMemTable == NULL) { if (pMemTable == NULL) {
(*pMAF->destroy)(pMAF, pMA); (*pMAF->destroy)(pMAF, pMA);
return NULL; return NULL;
...@@ -62,7 +62,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) { ...@@ -62,7 +62,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) {
pMemTable->keyMax = TSKEY_MIN; pMemTable->keyMax = TSKEY_MIN;
pMemTable->nRow = 0; pMemTable->nRow = 0;
pMemTable->pMA = pMA; pMemTable->pMA = pMA;
tSListInit(&(pMemTable->list)); TD_SLIST_INIT(&(pMemTable->list));
// TODO // TODO
return pMemTable; return pMemTable;
...@@ -71,7 +71,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) { ...@@ -71,7 +71,7 @@ STsdbMemTable *tsdbNewMemTable(SMemAllocatorFactory *pMAF) {
void tsdbFreeMemTable(SMemAllocatorFactory *pMAF, STsdbMemTable *pMemTable) { void tsdbFreeMemTable(SMemAllocatorFactory *pMAF, STsdbMemTable *pMemTable) {
SMemAllocator *pMA = pMemTable->pMA; SMemAllocator *pMA = pMemTable->pMA;
if (pMA->free) { if (TD_MA_FREE_FUNC(pMA) != NULL) {
// TODO // TODO
ASSERT(0); ASSERT(0);
} }
...@@ -81,12 +81,12 @@ void tsdbFreeMemTable(SMemAllocatorFactory *pMAF, STsdbMemTable *pMemTable) { ...@@ -81,12 +81,12 @@ void tsdbFreeMemTable(SMemAllocatorFactory *pMAF, STsdbMemTable *pMemTable) {
int tsdbInsertDataToMemTable(STsdbMemTable *pMemTable, SSubmitMsg *pMsg) { int tsdbInsertDataToMemTable(STsdbMemTable *pMemTable, SSubmitMsg *pMsg) {
SMemAllocator *pMA = pMemTable->pMA; SMemAllocator *pMA = pMemTable->pMA;
STbData * pTbData = (STbData *)((*pMA->malloc)(pMA, sizeof(*pTbData))); STbData * pTbData = (STbData *)TD_MA_MALLOC(pMA, sizeof(*pTbData));
if (pTbData == NULL) { if (pTbData == NULL) {
// TODO // TODO
} }
tSListPush(&(pMemTable->list), pTbData); TD_SLIST_PUSH(&(pMemTable->list), pTbData);
return 0; return 0;
} }
......
...@@ -10,4 +10,4 @@ add_subdirectory(catalog) ...@@ -10,4 +10,4 @@ add_subdirectory(catalog)
add_subdirectory(executor) add_subdirectory(executor)
add_subdirectory(planner) add_subdirectory(planner)
add_subdirectory(function) add_subdirectory(function)
add_subdirectory(query) add_subdirectory(qcom)
...@@ -8,7 +8,7 @@ target_include_directories( ...@@ -8,7 +8,7 @@ target_include_directories(
target_link_libraries( target_link_libraries(
catalog catalog
PRIVATE os util common transport query PRIVATE os util transport qcom
) )
ADD_SUBDIRECTORY(test) ADD_SUBDIRECTORY(test)
\ No newline at end of file
...@@ -8,7 +8,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) ...@@ -8,7 +8,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
ADD_EXECUTABLE(catalogTest ${SOURCE_LIST}) ADD_EXECUTABLE(catalogTest ${SOURCE_LIST})
TARGET_LINK_LIBRARIES( TARGET_LINK_LIBRARIES(
catalogTest catalogTest
PUBLIC os util common catalog transport gtest query taos PUBLIC os util common catalog transport gtest qcom taos
) )
TARGET_INCLUDE_DIRECTORIES( TARGET_INCLUDE_DIRECTORIES(
......
...@@ -9,6 +9,7 @@ target_link_libraries( ...@@ -9,6 +9,7 @@ target_link_libraries(
index index
PUBLIC os PUBLIC os
PUBLIC util PUBLIC util
PUBLIC common
) )
if (${BUILD_WITH_LUCENE}) if (${BUILD_WITH_LUCENE})
......
...@@ -37,9 +37,11 @@ struct SIndex { ...@@ -37,9 +37,11 @@ struct SIndex {
#endif #endif
void *cache; void *cache;
void *tindex; void *tindex;
SHashObj *fieldObj; // <field name, field id> SHashObj *fieldObj;// < field name, field id>
uint64_t suid;
int fieldId; int64_t suid; // current super table id, -1 is normal table
int fieldId; // field id allocated to cache
int32_t cVersion; // current version allocated to cache
pthread_mutex_t mtx; pthread_mutex_t mtx;
}; };
...@@ -58,6 +60,7 @@ struct SIndexMultiTermQuery { ...@@ -58,6 +60,7 @@ struct SIndexMultiTermQuery {
// field and key; // field and key;
typedef struct SIndexTerm { typedef struct SIndexTerm {
uint8_t type; // term data type, str/interger/json
char *key; char *key;
int32_t nKey; int32_t nKey;
char *val; char *val;
......
...@@ -17,11 +17,12 @@ ...@@ -17,11 +17,12 @@
#include "index.h" #include "index.h"
#include "tlockfree.h" #include "tlockfree.h"
#include "tskiplist.h"
// ----------------- row structure in skiplist --------------------- // ----------------- row structure in skiplist ---------------------
/* A data row, the format is like below: /* A data row, the format is like below:
* |<--totalLen-->|<-- fieldId-->|<-- value len--->|<-- value-->|<--version--->|<-- itermType -->| * content: |<--totalLen-->|<-- fieldid-->|<--field type -->|<-- value len--->|<-- value -->|<-- uid -->|<--version--->|<-- itermType -->|
* * len : |<--int32_t -->|<-- int16_t-->|<-- int16_t --->|<--- int32_t --->|<--valuelen->|<--uint64_t->|<-- int32_t-->|<-- int8_t --->|
*/ */
#ifdef __cplusplus #ifdef __cplusplus
...@@ -30,7 +31,7 @@ extern "C" { ...@@ -30,7 +31,7 @@ extern "C" {
typedef struct IndexCache { typedef struct IndexCache {
T_REF_DECLARE() T_REF_DECLARE()
int cVersion; // SSkipList *skiplist;
} IndexCache; } IndexCache;
...@@ -39,7 +40,8 @@ IndexCache *indexCacheCreate(); ...@@ -39,7 +40,8 @@ IndexCache *indexCacheCreate();
void indexCacheDestroy(IndexCache *cache); void indexCacheDestroy(IndexCache *cache);
int indexCachePut(IndexCache *cache, int32_t fieldId, const char *fieldVale, int32_t fvlen, uint64_t uid, int8_t operaType); int indexCachePut(IndexCache *cache, int16_t fieldId, int16_t fieldType, const char *fieldValue, int32_t fvLen,
uint32_t version, uint64_t uid, int8_t operType);
int indexCacheGet(IndexCache *cache, uint64_t *rst); int indexCacheGet(IndexCache *cache, uint64_t *rst);
int indexCacheSearch(IndexCache *cache, SIndexMultiTermQuery *query, SArray *result); int indexCacheSearch(IndexCache *cache, SIndexMultiTermQuery *query, SArray *result);
......
...@@ -315,7 +315,6 @@ typedef struct StreamWithStateResult { ...@@ -315,7 +315,6 @@ typedef struct StreamWithStateResult {
FstSlice data; FstSlice data;
FstOutput out; FstOutput out;
void *state; void *state;
} StreamWithStateResult; } StreamWithStateResult;
StreamWithStateResult *swsResultCreate(FstSlice *data, FstOutput fOut, void *state); StreamWithStateResult *swsResultCreate(FstSlice *data, FstOutput fOut, void *state);
......
...@@ -23,7 +23,8 @@ ...@@ -23,7 +23,8 @@
typedef struct SIdxFieldInfo { typedef struct SIdxFieldInfo {
int id; // generated by index internal int fieldId; // generated by index internal
int cVersion;
int type; // field type int type; // field type
} SIdxFieldInfo; } SIdxFieldInfo;
...@@ -39,7 +40,7 @@ static int indexMergeCacheIntoTindex(struct SIndex *sIdx) { ...@@ -39,7 +40,7 @@ static int indexMergeCacheIntoTindex(struct SIndex *sIdx) {
} }
SIndex *indexOpen(SIndexOpts *opts, const char *path) { SIndex *indexOpen(SIndexOpts *opts, const char *path) {
pthread_once(&isInit, indexInit); pthread_once(&isInit, indexInit);
SIndex *sIdx = malloc(sizeof(SIndex)); SIndex *sIdx = calloc(1, sizeof(SIndex));
#ifdef USE_LUCENE #ifdef USE_LUCENE
index_t *index = index_open(path); index_t *index = index_open(path);
...@@ -49,6 +50,8 @@ SIndex *indexOpen(SIndexOpts *opts, const char *path) { ...@@ -49,6 +50,8 @@ SIndex *indexOpen(SIndexOpts *opts, const char *path) {
sIdx->cache = (void*)indexCacheCreate(); sIdx->cache = (void*)indexCacheCreate();
sIdx->tindex = NULL; sIdx->tindex = NULL;
sIdx->fieldObj = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); sIdx->fieldObj = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
sIdx->fieldId = 1;
sIdx->cVersion = 1;
pthread_mutex_init(&sIdx->mtx, NULL); pthread_mutex_init(&sIdx->mtx, NULL);
return sIdx; return sIdx;
} }
...@@ -65,7 +68,7 @@ void indexClose(SIndex *sIdx) { ...@@ -65,7 +68,7 @@ void indexClose(SIndex *sIdx) {
return; return;
} }
int indexPut(SIndex *index, SArray* field_vals, int uid) { int indexPut(SIndex *index, SArray* fVals, int uid) {
#ifdef USE_LUCENE #ifdef USE_LUCENE
index_document_t *doc = index_document_create(); index_document_t *doc = index_document_create();
...@@ -73,8 +76,8 @@ int indexPut(SIndex *index, SArray* field_vals, int uid) { ...@@ -73,8 +76,8 @@ int indexPut(SIndex *index, SArray* field_vals, int uid) {
char buf[16] = {0}; char buf[16] = {0};
sprintf(buf, "%d", uid); sprintf(buf, "%d", uid);
for (int i = 0; i < taosArrayGetSize(field_vals); i++) { for (int i = 0; i < taosArrayGetSize(fVals); i++) {
SIndexTerm *p = taosArrayGetP(field_vals, i); SIndexTerm *p = taosArrayGetP(fVals, i);
index_document_add(doc, (const char *)(p->key), p->nKey, (const char *)(p->val), p->nVal, 1); index_document_add(doc, (const char *)(p->key), p->nKey, (const char *)(p->val), p->nVal, 1);
} }
index_document_add(doc, NULL, 0, buf, strlen(buf), 0); index_document_add(doc, NULL, 0, buf, strlen(buf), 0);
...@@ -82,10 +85,33 @@ int indexPut(SIndex *index, SArray* field_vals, int uid) { ...@@ -82,10 +85,33 @@ int indexPut(SIndex *index, SArray* field_vals, int uid) {
index_put(index->index, doc); index_put(index->index, doc);
index_document_destroy(doc); index_document_destroy(doc);
#endif #endif
//TODO(yihao): reduce the lock range
pthread_mutex_lock(&index->mtx); pthread_mutex_lock(&index->mtx);
for (int i = 0; i < taosArrayGetSize(fVals); i++) {
SIndexTerm *p = taosArrayGetP(fVals, i);
SIdxFieldInfo *fi = taosHashGet(index->fieldObj, p->key, p->nKey);
if (fi == NULL) {
SIdxFieldInfo tfi = {.fieldId = index->fieldId, .type = p->type};
index->cVersion++;
index->fieldId++;
taosHashPut(index->fieldObj, p->key, p->nKey, &tfi, sizeof(tfi));
} else {
//TODO, del
}
}
for (int i = 0; i < taosArrayGetSize(fVals); i++) {
SIndexTerm *p = taosArrayGetP(fVals, i);
SIdxFieldInfo *fi = taosHashGet(index->fieldObj, p->key, p->nKey);
assert(fi != NULL);
int32_t fieldId = fi->fieldId;
int32_t colType = fi->type;
int32_t version = index->cVersion;
}
pthread_mutex_unlock(&index->mtx); pthread_mutex_unlock(&index->mtx);
return 1; return 1;
} }
int indexSearch(SIndex *index, SIndexMultiTermQuery *multiQuerys, SArray *result) { int indexSearch(SIndex *index, SIndexMultiTermQuery *multiQuerys, SArray *result) {
#ifdef USE_LUCENE #ifdef USE_LUCENE
...@@ -152,7 +178,7 @@ SIndexMultiTermQuery *indexMultiTermQueryCreate(EIndexOperatorType opera) { ...@@ -152,7 +178,7 @@ SIndexMultiTermQuery *indexMultiTermQueryCreate(EIndexOperatorType opera) {
SIndexMultiTermQuery *p = (SIndexMultiTermQuery *)malloc(sizeof(SIndexMultiTermQuery)); SIndexMultiTermQuery *p = (SIndexMultiTermQuery *)malloc(sizeof(SIndexMultiTermQuery));
if (p == NULL) { return NULL; } if (p == NULL) { return NULL; }
p->opera = opera; p->opera = opera;
p->query = taosArrayInit(1, sizeof(SIndexTermQuery)); p->query = taosArrayInit(4, sizeof(SIndexTermQuery));
return p; return p;
} }
void indexMultiTermQueryDestroy(SIndexMultiTermQuery *pQuery) { void indexMultiTermQueryDestroy(SIndexMultiTermQuery *pQuery) {
......
...@@ -14,12 +14,18 @@ ...@@ -14,12 +14,18 @@
*/ */
#include "index_cache.h" #include "index_cache.h"
#include "tcompare.h"
#define MAX_INDEX_KEY_LEN 128 // test only, change later
static char* getIndexKey(const void *pData) {
return NULL;
}
static int32_t compareKey(const void *l, const void *r) { static int32_t compareKey(const void *l, const void *r) {
char *lp = (char *)l; char *lp = (char *)l;
char *rp = (char *)r; char *rp = (char *)r;
// skip total len // skip total len, not compare
int32_t ll, rl; // len int32_t ll, rl; // len
memcpy(&ll, lp, sizeof(int32_t)); memcpy(&ll, lp, sizeof(int32_t));
memcpy(&rl, rp, sizeof(int32_t)); memcpy(&rl, rp, sizeof(int32_t));
...@@ -27,7 +33,7 @@ static int32_t compareKey(const void *l, const void *r) { ...@@ -27,7 +33,7 @@ static int32_t compareKey(const void *l, const void *r) {
rp += sizeof(int32_t); rp += sizeof(int32_t);
// compare field id // compare field id
int32_t lf, rf; // field id int16_t lf, rf; // field id
memcpy(&lf, lp, sizeof(lf)); memcpy(&lf, lp, sizeof(lf));
memcpy(&rf, rp, sizeof(rf)); memcpy(&rf, rp, sizeof(rf));
if (lf != rf) { if (lf != rf) {
...@@ -36,14 +42,22 @@ static int32_t compareKey(const void *l, const void *r) { ...@@ -36,14 +42,22 @@ static int32_t compareKey(const void *l, const void *r) {
lp += sizeof(lf); lp += sizeof(lf);
rp += sizeof(rf); rp += sizeof(rf);
// compare field value // compare field type
int16_t lft, rft;
memcpy(&lft, lp, sizeof(lft));
memcpy(&rft, rp, sizeof(rft));
lp += sizeof(lft);
rp += sizeof(rft);
assert(rft == rft);
// skip value len
int32_t lfl, rfl; int32_t lfl, rfl;
memcpy(&lfl, lp, sizeof(lfl)); memcpy(&lfl, lp, sizeof(lfl));
memcpy(&rfl, rp, sizeof(rfl)); memcpy(&rfl, rp, sizeof(rfl));
lp += sizeof(lfl); lp += sizeof(lfl);
rp += sizeof(rfl); rp += sizeof(rfl);
//refator later // compare value
int32_t i, j; int32_t i, j;
for (i = 0, j = 0; i < lfl && j < rfl; i++, j++) { for (i = 0, j = 0; i < lfl && j < rfl; i++, j++) {
if (lp[i] == rp[j]) { continue; } if (lp[i] == rp[j]) { continue; }
...@@ -54,7 +68,14 @@ static int32_t compareKey(const void *l, const void *r) { ...@@ -54,7 +68,14 @@ static int32_t compareKey(const void *l, const void *r) {
lp += lfl; lp += lfl;
rp += rfl; rp += rfl;
// compare version // skip uid
uint64_t lu, ru;
memcpy(&lu, lp, sizeof(lu));
memcpy(&ru, rp, sizeof(ru));
lp += sizeof(lu);
rp += sizeof(ru);
// compare version, desc order
int32_t lv, rv; int32_t lv, rv;
memcpy(&lv, lp, sizeof(lv)); memcpy(&lv, lp, sizeof(lv));
memcpy(&rv, rp, sizeof(rv)); memcpy(&rv, rp, sizeof(rv));
...@@ -63,50 +84,64 @@ static int32_t compareKey(const void *l, const void *r) { ...@@ -63,50 +84,64 @@ static int32_t compareKey(const void *l, const void *r) {
} }
lp += sizeof(lv); lp += sizeof(lv);
rp += sizeof(rv); rp += sizeof(rv);
// not care item type
return 0; return 0;
} }
IndexCache *indexCacheCreate() { IndexCache *indexCacheCreate() {
IndexCache *cache = calloc(1, sizeof(IndexCache)); IndexCache *cache = calloc(1, sizeof(IndexCache));
cache->skiplist = tSkipListCreate(MAX_SKIP_LIST_LEVEL, TSDB_DATA_TYPE_BINARY, MAX_INDEX_KEY_LEN, compareKey, SL_ALLOW_DUP_KEY, getIndexKey);
return cache; return cache;
} }
void indexCacheDestroy(IndexCache *cache) { void indexCacheDestroy(IndexCache *cache) {
if (cache == NULL) { return; }
tSkipListDestroy(cache->skiplist);
free(cache); free(cache);
} }
int indexCachePut(IndexCache *cache, int32_t fieldId, const char *fieldValue, int32_t fvlen, uint64_t uid, int8_t operType) { int indexCachePut(IndexCache *cache, int16_t fieldId, int16_t fieldType, const char *fieldValue, int32_t fvLen,
uint32_t version, uint64_t uid, int8_t operType) {
if (cache == NULL) { return -1;} if (cache == NULL) { return -1;}
int32_t version = T_REF_INC(cache);
int32_t total = sizeof(int32_t) + sizeof(fieldId) + 4 + fvlen + sizeof(version) + sizeof(uid) + sizeof(operType); // encode data
int32_t total = sizeof(int32_t) + sizeof(fieldId) + sizeof(fieldType) + sizeof(fvLen) + fvLen + sizeof(version) + sizeof(uid) + sizeof(operType);
char *buf = calloc(1, total); char *buf = calloc(1, total);
char *p = buf; char *p = buf;
memcpy(buf, &total, sizeof(total)); memcpy(p, &total, sizeof(total));
total += total; p += sizeof(total);
memcpy(p, &fieldId, sizeof(fieldId));
p += sizeof(fieldId);
memcpy(p, &fieldType, sizeof(fieldType));
p += sizeof(fieldType);
memcpy(buf, &fieldId, sizeof(fieldId)); memcpy(p, &fvLen, sizeof(fvLen));
buf += sizeof(fieldId); p += sizeof(fvLen);
memcpy(p, fieldValue, fvLen);
p += fvLen;
memcpy(buf, &fvlen, sizeof(fvlen)); memcpy(p, &version, sizeof(version));
buf += sizeof(fvlen); p += sizeof(version);
memcpy(buf, fieldValue, fvlen);
buf += fvlen;
memcpy(buf, &version, sizeof(version)); memcpy(p, &uid, sizeof(uid));
buf += sizeof(version); p += sizeof(uid);
memcpy(buf, &uid, sizeof(uid)); memcpy(p, &operType, sizeof(operType));
buf += sizeof(uid); p += sizeof(operType);
memcpy(buf, &operType, sizeof(operType)); tSkipListPut(cache->skiplist, (void *)buf);
buf += sizeof(operType); // encode end
}
int indexCacheDel(IndexCache *cache, int32_t fieldId, const char *fieldValue, int32_t fvlen, uint64_t uid, int8_t operType) {
} }
int indexCacheSearch(IndexCache *cache, SIndexMultiTermQuery *query, SArray *result) { int indexCacheSearch(IndexCache *cache, SIndexMultiTermQuery *query, SArray *result) {
......
...@@ -8,7 +8,7 @@ target_include_directories( ...@@ -8,7 +8,7 @@ target_include_directories(
target_link_libraries( target_link_libraries(
parser parser
PRIVATE os util common catalog function transport query PRIVATE os util catalog function transport qcom
) )
ADD_SUBDIRECTORY(test) ADD_SUBDIRECTORY(test)
...@@ -171,8 +171,8 @@ typedef struct SCreateDbInfo { ...@@ -171,8 +171,8 @@ typedef struct SCreateDbInfo {
int8_t update; int8_t update;
int8_t cachelast; int8_t cachelast;
SArray *keep; SArray *keep;
int8_t dbType; // int8_t dbType;
int16_t partitions; // int16_t partitions;
} SCreateDbInfo; } SCreateDbInfo;
typedef struct SCreateFuncInfo { typedef struct SCreateFuncInfo {
......
...@@ -5,5 +5,7 @@ ...@@ -5,5 +5,7 @@
#include "taosmsg.h" #include "taosmsg.h"
SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int64_t id, char* msgBuf, int32_t msgLen); SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int64_t id, char* msgBuf, int32_t msgLen);
SShowMsg* buildShowMsg(SShowInfo* pShowInfo, int64_t id, char* msgBuf, int32_t msgLen);
SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, char* msgBuf, int32_t msgLen);
#endif // TDENGINE_ASTTOMSG_H #endif // TDENGINE_ASTTOMSG_H
...@@ -46,6 +46,7 @@ SInternalField* getInternalField(SFieldInfo* pFieldInfo, int32_t index); ...@@ -46,6 +46,7 @@ SInternalField* getInternalField(SFieldInfo* pFieldInfo, int32_t index);
int32_t parserValidateIdToken(SToken* pToken); int32_t parserValidateIdToken(SToken* pToken);
int32_t parserValidatePassword(SToken* pToken, SMsgBuf* pMsgBuf); int32_t parserValidatePassword(SToken* pToken, SMsgBuf* pMsgBuf);
int32_t parserValidateNameToken(SToken* pToken);
int32_t buildInvalidOperationMsg(SMsgBuf* pMsgBuf, const char* msg); int32_t buildInvalidOperationMsg(SMsgBuf* pMsgBuf, const char* msg);
int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr); int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr);
......
...@@ -966,9 +966,6 @@ void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo) { ...@@ -966,9 +966,6 @@ void setDefaultCreateDbOption(SCreateDbInfo *pDBInfo) {
pDBInfo->update = -1; pDBInfo->update = -1;
pDBInfo->cachelast = -1; pDBInfo->cachelast = -1;
pDBInfo->dbType = -1;
pDBInfo->partitions = -1;
memset(&pDBInfo->precision, 0, sizeof(SToken)); memset(&pDBInfo->precision, 0, sizeof(SToken));
} }
......
#include "parserInt.h" #include "parserInt.h"
#include "parserUtil.h"
SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int64_t id, char* msgBuf, int32_t msgLen) { SCreateUserMsg* buildUserManipulationMsg(SSqlInfo* pInfo, int64_t id, char* msgBuf, int32_t msgLen) {
SCreateUserMsg *pMsg = (SCreateUserMsg *)calloc(1, sizeof(SCreateUserMsg)); SCreateUserMsg* pMsg = (SCreateUserMsg*)calloc(1, sizeof(SCreateUserMsg));
if (pMsg == NULL) { if (pMsg == NULL) {
// tscError("0x%" PRIx64 " failed to malloc for query msg", id); // tscError("0x%" PRIx64 " failed to malloc for query msg", id);
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
return NULL; return NULL;
} }
SUserInfo *pUser = &pInfo->pMiscInfo->user; SUserInfo* pUser = &pInfo->pMiscInfo->user;
strncpy(pMsg->user, pUser->user.z, pUser->user.n); strncpy(pMsg->user, pUser->user.z, pUser->user.n);
pMsg->type = pUser->type; pMsg->type = pUser->type;
pMsg->superUser = (int8_t)pUser->type; pMsg->superUser = (int8_t)pUser->type;
if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) { if (pUser->type == TSDB_ALTER_USER_PRIVILEGES) {
// pMsg->privilege = (char)pCmd->count; // pMsg->privilege = (char)pCmd->count;
} else { } else {
strncpy(pMsg->pass, pUser->passwd.z, pUser->passwd.n); strncpy(pMsg->pass, pUser->passwd.z, pUser->passwd.n);
} }
return pMsg; return pMsg;
} }
SShowMsg* buildShowMsg(SShowInfo* pShowInfo, int64_t id, char* msgBuf, int32_t msgLen) {
SShowMsg* pShowMsg = calloc(1, sizeof(SShowMsg));
pShowMsg->type = pShowInfo->showType;
if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) {
SToken* pPattern = &pShowInfo->pattern;
if (pPattern->type > 0) { // only show tables support wildcard query
strncpy(pShowMsg->payload, pPattern->z, pPattern->n);
pShowMsg->payloadLen = htons(pPattern->n);
}
} else {
SToken* pEpAddr = &pShowInfo->prefix;
assert(pEpAddr->n > 0 && pEpAddr->type > 0);
strncpy(pShowMsg->payload, pEpAddr->z, pEpAddr->n);
pShowMsg->payloadLen = htons(pEpAddr->n);
}
return pShowMsg;
}
static int32_t setKeepOption(SCreateDbMsg* pMsg, const SCreateDbInfo* pCreateDb, SMsgBuf* pMsgBuf) {
const char* msg1 = "invalid number of keep options";
const char* msg2 = "invalid keep value";
const char* msg3 = "invalid keep value, should be keep0 <= keep1 <= keep2";
pMsg->daysToKeep0 = htonl(-1);
pMsg->daysToKeep1 = htonl(-1);
pMsg->daysToKeep2 = htonl(-1);
SArray* pKeep = pCreateDb->keep;
if (pKeep != NULL) {
size_t s = taosArrayGetSize(pKeep);
#ifdef _STORAGE
if (s >= 4 ||s <= 0) {
#else
if (s != 1) {
#endif
return buildInvalidOperationMsg(pMsgBuf, msg1);
}
// tListI* p0 = taosArrayGet(pKeep, 0);
// tVariantListItem* p1 = (s > 1) ? taosArrayGet(pKeep, 1) : p0;
// tVariantListItem* p2 = (s > 2) ? taosArrayGet(pKeep, 2) : p1;
//
// if ((int32_t)p0->pVar.i64 <= 0 || (int32_t)p1->pVar.i64 <= 0 || (int32_t)p2->pVar.i64 <= 0) {
// return buildInvalidOperationMsg(pMsgBuf, msg2);
// }
// if (!(((int32_t)p0->pVar.i64 <= (int32_t)p1->pVar.i64) && ((int32_t)p1->pVar.i64 <= (int32_t)p2->pVar.i64))) {
// return buildInvalidOperationMsg(pMsgBuf, msg3);
// }
//
// pMsg->daysToKeep0 = htonl((int32_t)p0->pVar.i64);
// pMsg->daysToKeep1 = htonl((int32_t)p1->pVar.i64);
// pMsg->daysToKeep2 = htonl((int32_t)p2->pVar.i64);
}
return TSDB_CODE_SUCCESS;
}
static int32_t setTimePrecision(SCreateDbMsg* pMsg, const SCreateDbInfo* pCreateDbInfo, SMsgBuf* pMsgBuf) {
const char* msg = "invalid time precision";
pMsg->precision = TSDB_TIME_PRECISION_MILLI; // millisecond by default
SToken* pToken = &pCreateDbInfo->precision;
if (pToken->n > 0) {
pToken->n = strdequote(pToken->z);
if (strncmp(pToken->z, TSDB_TIME_PRECISION_MILLI_STR, pToken->n) == 0 &&
strlen(TSDB_TIME_PRECISION_MILLI_STR) == pToken->n) {
// time precision for this db: million second
pMsg->precision = TSDB_TIME_PRECISION_MILLI;
} else if (strncmp(pToken->z, TSDB_TIME_PRECISION_MICRO_STR, pToken->n) == 0 &&
strlen(TSDB_TIME_PRECISION_MICRO_STR) == pToken->n) {
pMsg->precision = TSDB_TIME_PRECISION_MICRO;
} else if (strncmp(pToken->z, TSDB_TIME_PRECISION_NANO_STR, pToken->n) == 0 &&
strlen(TSDB_TIME_PRECISION_NANO_STR) == pToken->n) {
pMsg->precision = TSDB_TIME_PRECISION_NANO;
} else {
return buildInvalidOperationMsg(pMsgBuf, msg);
}
}
return TSDB_CODE_SUCCESS;
}
static void doSetDbOptions(SCreateDbMsg* pMsg, const SCreateDbInfo* pCreateDb) {
pMsg->cacheBlockSize = htonl(pCreateDb->cacheBlockSize);
pMsg->totalBlocks = htonl(pCreateDb->numOfBlocks);
pMsg->daysPerFile = htonl(pCreateDb->daysPerFile);
pMsg->commitTime = htonl((int32_t)pCreateDb->commitTime);
pMsg->minRowsPerFileBlock = htonl(pCreateDb->minRowsPerBlock);
pMsg->maxRowsPerFileBlock = htonl(pCreateDb->maxRowsPerBlock);
pMsg->fsyncPeriod = htonl(pCreateDb->fsyncPeriod);
pMsg->compression = pCreateDb->compressionLevel;
pMsg->walLevel = (char)pCreateDb->walLevel;
pMsg->replications = pCreateDb->replica;
pMsg->quorum = pCreateDb->quorum;
pMsg->ignoreExist = pCreateDb->ignoreExists;
pMsg->update = pCreateDb->update;
pMsg->cacheLastRow = pCreateDb->cachelast;
}
int32_t setDbOptions(SCreateDbMsg* pCreateDbMsg, const SCreateDbInfo* pCreateDbSql, SMsgBuf* pMsgBuf) {
doSetDbOptions(pCreateDbMsg, pCreateDbSql);
if (setKeepOption(pCreateDbMsg, pCreateDbSql, pMsgBuf) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
if (setTimePrecision(pCreateDbMsg, pCreateDbSql, pMsgBuf) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
// todo configurable
pCreateDbMsg->numOfVgroups = htonl(2);
return TSDB_CODE_SUCCESS;
}
SCreateDbMsg* buildCreateDbMsg(SCreateDbInfo* pCreateDbInfo, char* msgBuf, int32_t msgLen) {
SCreateDbMsg* pCreateMsg = calloc(1, sizeof(SCreateDbMsg));
SMsgBuf msg = {.buf = msgBuf, .len = msgLen};
if (setDbOptions(pCreateMsg, pCreateDbInfo, &msg) != TSDB_CODE_SUCCESS) {
tfree(pCreateMsg);
terrno = TSDB_CODE_TSC_INVALID_OPERATION;
return NULL;
}
return pCreateMsg;
}
...@@ -759,11 +759,6 @@ int32_t validateIntervalNode(SQueryStmtInfo *pQueryInfo, SSqlNode* pSqlNode, SMs ...@@ -759,11 +759,6 @@ int32_t validateIntervalNode(SQueryStmtInfo *pQueryInfo, SSqlNode* pSqlNode, SMs
// It is a time window query // It is a time window query
pQueryInfo->info.timewindow = true; pQueryInfo->info.timewindow = true;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
// disable it temporarily
// bool interpQuery = tscIsPointInterpQuery(pQueryInfo);
// if ((pSqlNode->interval.token == TK_EVERY && (!interpQuery)) || (pSqlNode->interval.token == TK_INTERVAL && interpQuery)) {
// return buildInvalidOperationMsg(pMsgBuf, msg4);
// }
} }
int32_t validateSessionNode(SQueryStmtInfo *pQueryInfo, SSessionWindowVal* pSession, int32_t precision, SMsgBuf* pMsgBuf) { int32_t validateSessionNode(SQueryStmtInfo *pQueryInfo, SSessionWindowVal* pSession, int32_t precision, SMsgBuf* pMsgBuf) {
...@@ -3707,14 +3702,6 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer ...@@ -3707,14 +3702,6 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
case TSDB_SQL_SHOW: {
if (setShowInfo(pSql, pInfo) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
}
case TSDB_SQL_CREATE_FUNCTION: case TSDB_SQL_CREATE_FUNCTION:
case TSDB_SQL_DROP_FUNCTION: { case TSDB_SQL_DROP_FUNCTION: {
code = handleUserDefinedFunc(pSql, pInfo); code = handleUserDefinedFunc(pSql, pInfo);
...@@ -3725,35 +3712,6 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer ...@@ -3725,35 +3712,6 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pInfo, SQuer
break; break;
} }
case TSDB_SQL_ALTER_DB:
case TSDB_SQL_CREATE_DB: {
const char* msg1 = "invalid db name";
const char* msg2 = "name too long";
SCreateDbInfo* pCreateDB = &(pInfo->pMiscInfo->dbOpt);
if (pCreateDB->dbname.n >= TSDB_DB_NAME_LEN) {
return buildInvalidOperationMsg(pMsgBuf, msg2);
}
char buf[TSDB_DB_NAME_LEN] = {0};
SToken token = taosTokenDup(&pCreateDB->dbname, buf, tListLen(buf));
if (tscValidateName(&token) != TSDB_CODE_SUCCESS) {
return buildInvalidOperationMsg(pMsgBuf, msg1);
}
int32_t ret = tNameSetDbName(&pTableMetaInfo->name, getAccountId(pSql), &token);
if (ret != TSDB_CODE_SUCCESS) {
return buildInvalidOperationMsg(pMsgBuf, msg2);
}
if (parseCreateDBOptions(pCmd, pCreateDB) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
break;
}
case TSDB_SQL_CREATE_DNODE: { case TSDB_SQL_CREATE_DNODE: {
const char* msg = "invalid host name (ip address)"; const char* msg = "invalid host name (ip address)";
...@@ -4133,25 +4091,83 @@ static int32_t setShowInfo(struct SSqlInfo* pInfo, void** output, int32_t* msgLe ...@@ -4133,25 +4091,83 @@ static int32_t setShowInfo(struct SSqlInfo* pInfo, void** output, int32_t* msgLe
} }
} }
SShowMsg* pShowMsg = calloc(1, sizeof(SShowMsg)); *output = buildShowMsg(pShowInfo, 0, pMsgBuf->buf, pMsgBuf->len);
pShowMsg->type = pShowInfo->showType; *msgLen = sizeof(SShowMsg)/* + htons(pShowMsg->payloadLen)*/;
return TSDB_CODE_SUCCESS;
}
if (pShowInfo->showType != TSDB_MGMT_TABLE_VNODES) { // can only perform the parameters based on the macro definitation
SToken* pPattern = &pShowInfo->pattern; static int32_t doCheckDbOptions(SCreateDbMsg* pCreate, SMsgBuf* pMsgBuf) {
if (pPattern->type > 0) { // only show tables support wildcard query char msg[512] = {0};
strncpy(pShowMsg->payload, pPattern->z, pPattern->n);
pShowMsg->payloadLen = htons(pPattern->n); if (pCreate->walLevel != -1 && (pCreate->walLevel < TSDB_MIN_WAL_LEVEL || pCreate->walLevel > TSDB_MAX_WAL_LEVEL)) {
snprintf(msg, tListLen(msg), "invalid db option walLevel: %d, only 1-2 allowed", pCreate->walLevel);
return buildInvalidOperationMsg(pMsgBuf, msg);
} }
} else {
SToken* pEpAddr = &pShowInfo->prefix;
assert(pEpAddr->n > 0 && pEpAddr->type > 0);
strncpy(pShowMsg->payload, pEpAddr->z, pEpAddr->n); if (pCreate->replications != -1 &&
pShowMsg->payloadLen = htons(pEpAddr->n); (pCreate->replications < TSDB_MIN_DB_REPLICA_OPTION || pCreate->replications > TSDB_MAX_DB_REPLICA_OPTION)) {
snprintf(msg, tListLen(msg), "invalid db option replications: %d valid range: [%d, %d]", pCreate->replications,
TSDB_MIN_DB_REPLICA_OPTION, TSDB_MAX_DB_REPLICA_OPTION);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
int32_t blocks = ntohl(pCreate->totalBlocks);
if (blocks != -1 && (blocks < TSDB_MIN_TOTAL_BLOCKS || blocks > TSDB_MAX_TOTAL_BLOCKS)) {
snprintf(msg, tListLen(msg), "invalid db option totalBlocks: %d valid range: [%d, %d]", blocks,
TSDB_MIN_TOTAL_BLOCKS, TSDB_MAX_TOTAL_BLOCKS);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
if (pCreate->quorum != -1 &&
(pCreate->quorum < TSDB_MIN_DB_QUORUM_OPTION || pCreate->quorum > TSDB_MAX_DB_QUORUM_OPTION)) {
snprintf(msg, tListLen(msg), "invalid db option quorum: %d valid range: [%d, %d]", pCreate->quorum,
TSDB_MIN_DB_QUORUM_OPTION, TSDB_MAX_DB_QUORUM_OPTION);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
int32_t val = htonl(pCreate->daysPerFile);
if (val != -1 && (val < TSDB_MIN_DAYS_PER_FILE || val > TSDB_MAX_DAYS_PER_FILE)) {
snprintf(msg, tListLen(msg), "invalid db option daysPerFile: %d valid range: [%d, %d]", val,
TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
val = htonl(pCreate->cacheBlockSize);
if (val != -1 && (val < TSDB_MIN_CACHE_BLOCK_SIZE || val > TSDB_MAX_CACHE_BLOCK_SIZE)) {
snprintf(msg, tListLen(msg), "invalid db option cacheBlockSize: %d valid range: [%d, %d]", val,
TSDB_MIN_CACHE_BLOCK_SIZE, TSDB_MAX_CACHE_BLOCK_SIZE);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
if (pCreate->precision != TSDB_TIME_PRECISION_MILLI && pCreate->precision != TSDB_TIME_PRECISION_MICRO &&
pCreate->precision != TSDB_TIME_PRECISION_NANO) {
snprintf(msg, tListLen(msg), "invalid db option timePrecision: %d valid value: [%d, %d, %d]", pCreate->precision,
TSDB_TIME_PRECISION_MILLI, TSDB_TIME_PRECISION_MICRO, TSDB_TIME_PRECISION_NANO);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
val = htonl(pCreate->commitTime);
if (val != -1 && (val < TSDB_MIN_COMMIT_TIME || val > TSDB_MAX_COMMIT_TIME)) {
snprintf(msg, tListLen(msg), "invalid db option commitTime: %d valid range: [%d, %d]", val,
TSDB_MIN_COMMIT_TIME, TSDB_MAX_COMMIT_TIME);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
val = htonl(pCreate->fsyncPeriod);
if (val != -1 && (val < TSDB_MIN_FSYNC_PERIOD || val > TSDB_MAX_FSYNC_PERIOD)) {
snprintf(msg, tListLen(msg), "invalid db option fsyncPeriod: %d valid range: [%d, %d]", val,
TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD);
return buildInvalidOperationMsg(pMsgBuf, msg);
}
if (pCreate->compression != -1 &&
(pCreate->compression < TSDB_MIN_COMP_LEVEL || pCreate->compression > TSDB_MAX_COMP_LEVEL)) {
snprintf(msg, tListLen(msg), "invalid db option compression: %d valid range: [%d, %d]", pCreate->compression,
TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL);
return buildInvalidOperationMsg(pMsgBuf, msg);
} }
*output = pShowMsg;
*msgLen = sizeof(SShowMsg) + htons(pShowMsg->payloadLen);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -4216,6 +4232,36 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, int64_t id, void** output, in ...@@ -4216,6 +4232,36 @@ int32_t qParserValidateDclSqlNode(SSqlInfo* pInfo, int64_t id, void** output, in
code = setShowInfo(pInfo, output, outputLen, pMsgBuf); code = setShowInfo(pInfo, output, outputLen, pMsgBuf);
break; break;
} }
case TSDB_SQL_ALTER_DB:
case TSDB_SQL_CREATE_DB: {
const char* msg1 = "invalid db name";
const char* msg2 = "name too long";
SCreateDbInfo* pCreateDB = &(pInfo->pMiscInfo->dbOpt);
if (pCreateDB->dbname.n >= TSDB_DB_NAME_LEN) {
return buildInvalidOperationMsg(pMsgBuf, msg2);
}
char buf[TSDB_DB_NAME_LEN] = {0};
SToken token = taosTokenDup(&pCreateDB->dbname, buf, tListLen(buf));
if (parserValidateNameToken(&token) != TSDB_CODE_SUCCESS) {
return buildInvalidOperationMsg(pMsgBuf, msg1);
}
SCreateDbMsg* pCreateMsg = buildCreateDbMsg(pCreateDB, pMsgBuf->buf, pMsgBuf->len);
if (doCheckDbOptions(pCreateMsg, pMsgBuf) != TSDB_CODE_SUCCESS) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
strncpy(pCreateMsg->db, token.z, token.n);
*output = pCreateMsg;
*outputLen = sizeof(SCreateDbMsg);
break;
}
default: default:
break; break;
} }
......
...@@ -77,6 +77,14 @@ typedef struct SInsertParseContext { ...@@ -77,6 +77,14 @@ typedef struct SInsertParseContext {
SInsertStmtInfo* pOutput; SInsertStmtInfo* pOutput;
} SInsertParseContext; } SInsertParseContext;
typedef int32_t (*FRowAppend)(const void *value, int32_t len, void *param);
typedef struct SKvParam {
char buf[TSDB_MAX_TAGS_LEN];
SKVRowBuilder* builder;
SSchema* schema;
} SKvParam;
static uint8_t TRUE_VALUE = (uint8_t)TSDB_TRUE; static uint8_t TRUE_VALUE = (uint8_t)TSDB_TRUE;
static uint8_t FALSE_VALUE = (uint8_t)TSDB_FALSE; static uint8_t FALSE_VALUE = (uint8_t)TSDB_FALSE;
...@@ -300,14 +308,6 @@ static int parseTime(SInsertParseContext* pCxt, SToken *pToken, int16_t timePrec ...@@ -300,14 +308,6 @@ static int parseTime(SInsertParseContext* pCxt, SToken *pToken, int16_t timePrec
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
typedef int32_t (*FRowAppend)(const void *value, int32_t len, void *param);
typedef struct SKvParam {
char buf[TSDB_MAX_TAGS_LEN];
SKVRowBuilder* builder;
SSchema* schema;
} SKvParam;
static FORCE_INLINE int32_t KvRowAppend(const void *value, int32_t len, void *param) { static FORCE_INLINE int32_t KvRowAppend(const void *value, int32_t len, void *param) {
SKvParam* pa = (SKvParam*)param; SKvParam* pa = (SKvParam*)param;
if (TSDB_DATA_TYPE_BINARY == pa->schema->type) { if (TSDB_DATA_TYPE_BINARY == pa->schema->type) {
......
...@@ -32,12 +32,6 @@ bool qIsInsertSql(const char* pStr, size_t length) { ...@@ -32,12 +32,6 @@ bool qIsInsertSql(const char* pStr, size_t length) {
} }
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) { 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) {
SQueryStmtInfo* pQueryInfo = calloc(1, sizeof(SQueryStmtInfo));
if (pQueryInfo == NULL) {
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; // set correct error code.
return terrno;
}
SSqlInfo info = doGenerateAST(pStr); SSqlInfo info = doGenerateAST(pStr);
if (!info.valid) { if (!info.valid) {
strncpy(msg, info.msg, msgLen); strncpy(msg, info.msg, msgLen);
...@@ -51,6 +45,12 @@ int32_t qParseQuerySql(const char* pStr, size_t length, int64_t id, int32_t *typ ...@@ -51,6 +45,12 @@ int32_t qParseQuerySql(const char* pStr, size_t length, int64_t id, int32_t *typ
// do nothing // do nothing
} }
} else { } else {
SQueryStmtInfo* pQueryInfo = calloc(1, sizeof(SQueryStmtInfo));
if (pQueryInfo == NULL) {
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; // set correct error code.
return terrno;
}
struct SCatalog* pCatalog = NULL; struct SCatalog* pCatalog = NULL;
int32_t code = catalogGetHandle(NULL, &pCatalog); int32_t code = catalogGetHandle(NULL, &pCatalog);
code = qParserValidateSqlNode(pCatalog, &info, pQueryInfo, id, msg, msgLen); code = qParserValidateSqlNode(pCatalog, &info, pQueryInfo, id, msg, msgLen);
...@@ -59,6 +59,7 @@ int32_t qParseQuerySql(const char* pStr, size_t length, int64_t id, int32_t *typ ...@@ -59,6 +59,7 @@ int32_t qParseQuerySql(const char* pStr, size_t length, int64_t id, int32_t *typ
} }
} }
destroySqlInfo(&info);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
...@@ -76,7 +77,7 @@ static int32_t tnameComparFn(const void* p1, const void* p2) { ...@@ -76,7 +77,7 @@ static int32_t tnameComparFn(const void* p1, const void* p2) {
SName* pn1 = (SName*)p1; SName* pn1 = (SName*)p1;
SName* pn2 = (SName*)p2; SName* pn2 = (SName*)p2;
int32_t ret = strncmp(pn1->acctId, pn2->acctId, tListLen(pn1->acctId)); int32_t ret = pn1->acctId - pn2->acctId;
if (ret != 0) { if (ret != 0) {
return ret > 0? 1:-1; return ret > 0? 1:-1;
} else { } else {
......
...@@ -122,6 +122,25 @@ int32_t parserValidatePassword(SToken* pToken, SMsgBuf* pMsgBuf) { ...@@ -122,6 +122,25 @@ int32_t parserValidatePassword(SToken* pToken, SMsgBuf* pMsgBuf) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t parserValidateNameToken(SToken* pToken) {
if (pToken == NULL || pToken->z == NULL || pToken->type != TK_ID) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
// it is a token quoted with escape char '`'
if (pToken->z[0] == TS_ESCAPE_CHAR && pToken->z[pToken->n - 1] == TS_ESCAPE_CHAR) {
return TSDB_CODE_SUCCESS;
}
char* sep = strnchr(pToken->z, TS_PATH_DELIMITER[0], pToken->n, true);
if (sep != NULL) { // It is a complex type, not allow
return TSDB_CODE_TSC_INVALID_OPERATION;
}
strntolower(pToken->z, pToken->z, pToken->n);
return TSDB_CODE_SUCCESS;
}
int32_t buildInvalidOperationMsg(SMsgBuf* pBuf, const char* msg) { int32_t buildInvalidOperationMsg(SMsgBuf* pBuf, const char* msg) {
strncpy(pBuf->buf, msg, pBuf->len); strncpy(pBuf->buf, msg, pBuf->len);
return TSDB_CODE_TSC_INVALID_OPERATION; return TSDB_CODE_TSC_INVALID_OPERATION;
......
...@@ -2519,7 +2519,7 @@ static void yy_reduce( ...@@ -2519,7 +2519,7 @@ static void yy_reduce(
{ yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; } { yymsp[-1].minor.yy0 = yymsp[0].minor.yy0; }
break; break;
case 105: /* db_optr ::= */ case 105: /* db_optr ::= */
{setDefaultCreateDbOption(&yymsp[1].minor.yy256); yymsp[1].minor.yy256.dbType = TSDB_DB_TYPE_DEFAULT;} {setDefaultCreateDbOption(&yymsp[1].minor.yy256);}
break; break;
case 106: /* db_optr ::= db_optr cache */ case 106: /* db_optr ::= db_optr cache */
{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.cacheBlockSize = strtol(yymsp[0].minor.yy0.z, NULL, 10); }
...@@ -2590,16 +2590,16 @@ static void yy_reduce( ...@@ -2590,16 +2590,16 @@ static void yy_reduce(
break; break;
case 121: /* topic_optr ::= db_optr */ case 121: /* topic_optr ::= db_optr */
case 131: /* alter_topic_optr ::= alter_db_optr */ yytestcase(yyruleno==131); case 131: /* alter_topic_optr ::= alter_db_optr */ yytestcase(yyruleno==131);
{ yylhsminor.yy256 = yymsp[0].minor.yy256; yylhsminor.yy256.dbType = TSDB_DB_TYPE_TOPIC; } { yylhsminor.yy256 = yymsp[0].minor.yy256;}
yymsp[0].minor.yy256 = yylhsminor.yy256; yymsp[0].minor.yy256 = yylhsminor.yy256;
break; break;
case 122: /* topic_optr ::= topic_optr partitions */ case 122: /* topic_optr ::= topic_optr partitions */
case 132: /* alter_topic_optr ::= alter_topic_optr partitions */ yytestcase(yyruleno==132); case 132: /* alter_topic_optr ::= alter_topic_optr partitions */ yytestcase(yyruleno==132);
{ yylhsminor.yy256 = yymsp[-1].minor.yy256; yylhsminor.yy256.partitions = strtol(yymsp[0].minor.yy0.z, NULL, 10); } { yylhsminor.yy256 = yymsp[-1].minor.yy256; }
yymsp[-1].minor.yy256 = yylhsminor.yy256; yymsp[-1].minor.yy256 = yylhsminor.yy256;
break; break;
case 123: /* alter_db_optr ::= */ case 123: /* alter_db_optr ::= */
{ setDefaultCreateDbOption(&yymsp[1].minor.yy256); yymsp[1].minor.yy256.dbType = TSDB_DB_TYPE_DEFAULT;} { setDefaultCreateDbOption(&yymsp[1].minor.yy256); }
break; break;
case 133: /* typename ::= ids */ case 133: /* typename ::= ids */
{ {
......
...@@ -15,7 +15,7 @@ TARGET_INCLUDE_DIRECTORIES( ...@@ -15,7 +15,7 @@ TARGET_INCLUDE_DIRECTORIES(
TARGET_LINK_LIBRARIES( TARGET_LINK_LIBRARIES(
parserTest parserTest
PUBLIC os util common parser catalog transport gtest function planner query PUBLIC os util common parser catalog transport gtest function planner qcom
) )
TARGET_LINK_OPTIONS(parserTest PRIVATE -Wl,-wrap,malloc) TARGET_LINK_OPTIONS(parserTest PRIVATE -Wl,-wrap,malloc)
...@@ -8,7 +8,7 @@ target_include_directories( ...@@ -8,7 +8,7 @@ target_include_directories(
target_link_libraries( target_link_libraries(
planner planner
PRIVATE os util common catalog parser transport function query PRIVATE os util catalog cjson parser transport function qcom
) )
ADD_SUBDIRECTORY(test) ADD_SUBDIRECTORY(test)
...@@ -100,14 +100,9 @@ int32_t queryPlanToString(struct SQueryPlanNode* pQueryNode, char** str); ...@@ -100,14 +100,9 @@ int32_t queryPlanToString(struct SQueryPlanNode* pQueryNode, char** str);
int32_t queryPlanToSql(struct SQueryPlanNode* pQueryNode, char** sql); int32_t queryPlanToSql(struct SQueryPlanNode* pQueryNode, char** sql);
int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag); int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryDag** pDag);
int32_t setSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SArray* eps);
/** int32_t subPlanToString(const SSubplan *pPhyNode, char** str);
* Convert to physical plan to string to enable to print it out in the shell. int32_t stringToSubplan(const char* str, SSubplan** subplan);
* @param pPhyNode
* @param str
* @return
*/
int32_t phyPlanToString(struct SPhyNode *pPhyNode, char** str);
/** /**
* Destroy the query plan object. * Destroy the query plan object.
...@@ -122,6 +117,8 @@ void destroyQueryPlan(struct SQueryPlanNode* pQueryNode); ...@@ -122,6 +117,8 @@ void destroyQueryPlan(struct SQueryPlanNode* pQueryNode);
*/ */
void* destroyQueryPhyPlan(struct SPhyNode* pQueryPhyNode); void* destroyQueryPhyPlan(struct SPhyNode* pQueryPhyNode);
int32_t opNameToOpType(const char* name);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -19,6 +19,13 @@ ...@@ -19,6 +19,13 @@
#define STORE_CURRENT_SUBPLAN(cxt) SSubplan* _ = cxt->pCurrentSubplan #define STORE_CURRENT_SUBPLAN(cxt) SSubplan* _ = cxt->pCurrentSubplan
#define RECOVERY_CURRENT_SUBPLAN(cxt) cxt->pCurrentSubplan = _ #define RECOVERY_CURRENT_SUBPLAN(cxt) cxt->pCurrentSubplan = _
typedef struct SPlanContext {
struct SCatalog* pCatalog;
struct SQueryDag* pDag;
SSubplan* pCurrentSubplan;
SSubplanId nextId;
} SPlanContext;
static const char* gOpName[] = { static const char* gOpName[] = {
"Unknown", "Unknown",
#define INCLUDE_AS_NAME #define INCLUDE_AS_NAME
...@@ -26,12 +33,14 @@ static const char* gOpName[] = { ...@@ -26,12 +33,14 @@ static const char* gOpName[] = {
#undef INCLUDE_AS_NAME #undef INCLUDE_AS_NAME
}; };
typedef struct SPlanContext { int32_t opNameToOpType(const char* name) {
struct SCatalog* pCatalog; for (int32_t i = 1; i < sizeof(gOpName) / sizeof(gOpName[0]); ++i) {
struct SQueryDag* pDag; if (strcmp(name, gOpName[i])) {
SSubplan* pCurrentSubplan; return i;
SSubplanId nextId; }
} SPlanContext; }
return OP_Unknown;
}
static void toDataBlockSchema(SQueryPlanNode* pPlanNode, SDataBlockSchema* dataBlockSchema) { static void toDataBlockSchema(SQueryPlanNode* pPlanNode, SDataBlockSchema* dataBlockSchema) {
SWAP(dataBlockSchema->pSchema, pPlanNode->pSchema, SSchema*); SWAP(dataBlockSchema->pSchema, pPlanNode->pSchema, SSchema*);
...@@ -179,7 +188,7 @@ static SPhyNode* createPhyNode(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) { ...@@ -179,7 +188,7 @@ static SPhyNode* createPhyNode(SPlanContext* pCxt, SQueryPlanNode* pPlanNode) {
assert(false); assert(false);
} }
if (pPlanNode->pChildren != NULL && taosArrayGetSize(pPlanNode->pChildren) > 0) { if (pPlanNode->pChildren != NULL && taosArrayGetSize(pPlanNode->pChildren) > 0) {
node->pChildren = taosArrayInit(4, POINTER_BYTES); node->pChildren = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES);
size_t size = taosArrayGetSize(pPlanNode->pChildren); size_t size = taosArrayGetSize(pPlanNode->pChildren);
for(int32_t i = 0; i < size; ++i) { for(int32_t i = 0; i < size; ++i) {
SPhyNode* child = createPhyNode(pCxt, taosArrayGet(pPlanNode->pChildren, i)); SPhyNode* child = createPhyNode(pCxt, taosArrayGet(pPlanNode->pChildren, i));
...@@ -216,6 +225,6 @@ int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryD ...@@ -216,6 +225,6 @@ int32_t createDag(SQueryPlanNode* pQueryNode, struct SCatalog* pCatalog, SQueryD
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t subPlanToString(struct SSubplan *pPhyNode, char** str) { int32_t setSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SArray* eps) {
return TSDB_CODE_SUCCESS; //todo
} }
/*
* 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 "plannerInt.h"
#include "parser.h"
#include "cJSON.h"
typedef bool (*FToJson)(const void* obj, cJSON* json);
typedef bool (*FFromJson)(const cJSON* json, void* obj);
static bool addObject(cJSON* json, const char* name, FToJson func, const void* obj) {
if (NULL == obj) {
return true;
}
cJSON* jObj = cJSON_CreateObject();
if (NULL == jObj || !func(obj, jObj)) {
cJSON_Delete(jObj);
return false;
}
return cJSON_AddItemToObject(json, name, jObj);
}
static bool addItem(cJSON* json, FToJson func, const void* obj) {
cJSON* jObj = cJSON_CreateObject();
if (NULL == jObj || !func(obj, jObj)) {
cJSON_Delete(jObj);
return false;
}
return cJSON_AddItemToArray(json, jObj);
}
static bool fromObject(const cJSON* json, const char* name, FFromJson func, void* obj, bool required) {
cJSON* jObj = cJSON_GetObjectItem(json, name);
if (NULL == jObj) {
return !required;
}
return func(jObj, obj);
}
static bool fromObjectWithAlloc(const cJSON* json, const char* name, FFromJson func, void** obj, int32_t size, bool required) {
cJSON* jObj = cJSON_GetObjectItem(json, name);
if (NULL == jObj) {
return !required;
}
*obj = calloc(1, size);
if (NULL == *obj) {
return false;
}
return func(jObj, *obj);
}
static bool addArray(cJSON* json, const char* name, FToJson func, const SArray* array) {
size_t size = (NULL == array) ? 0 : taosArrayGetSize(array);
if (size > 0) {
cJSON* jArray = cJSON_AddArrayToObject(json, name);
if (NULL == jArray) {
return false;
}
for (size_t i = 0; i < size; ++i) {
if (!addItem(jArray, func, taosArrayGetP(array, i))) {
return false;
}
}
}
return true;
}
static bool fromArray(const cJSON* json, const char* name, FFromJson func, SArray** array, int32_t itemSize) {
const cJSON* jArray = cJSON_GetObjectItem(json, name);
int32_t size = (NULL == jArray ? 0 : cJSON_GetArraySize(jArray));
if (size > 0) {
*array = taosArrayInit(size, POINTER_BYTES);
if (NULL == *array) {
return false;
}
}
for (int32_t i = 0; i < size; ++i) {
void* item = calloc(1, itemSize);
if (NULL == item || !func(cJSON_GetArrayItem(jArray, i), item)) {
return false;
}
taosArrayPush(*array, &item);
}
return true;
}
static bool addRawArray(cJSON* json, const char* name, FToJson func, const void* array, int32_t itemSize, int32_t size) {
if (size > 0) {
cJSON* jArray = cJSON_AddArrayToObject(json, name);
if (NULL == jArray) {
return false;
}
for (size_t i = 0; i < size; ++i) {
if (!addItem(jArray, func, (const char*)array + itemSize * i)) {
return false;
}
}
}
return true;
}
static const cJSON* getArray(const cJSON* json, const char* name, int32_t* size) {
const cJSON* jArray = cJSON_GetObjectItem(json, name);
*size = (NULL == jArray ? 0 : cJSON_GetArraySize(jArray));
return jArray;
}
static bool fromItem(const cJSON* jArray, FFromJson func, void* array, int32_t itemSize, int32_t size) {
for (int32_t i = 0; i < size; ++i) {
if (!func(cJSON_GetArrayItem(jArray, i), (char*)array + itemSize)) {
return false;
}
}
return true;
}
static bool fromRawArrayWithAlloc(const cJSON* json, const char* name, FFromJson func, void** array, int32_t itemSize, int32_t* size) {
const cJSON* jArray = getArray(json, name, size);
if (*size > 0) {
*array = calloc(1, itemSize * (*size));
if (NULL == *array) {
return false;
}
}
return fromItem(jArray, func, *array, itemSize, *size);
}
static bool fromRawArray(const cJSON* json, const char* name, FFromJson func, void* array, int32_t itemSize, int32_t* size) {
const cJSON* jArray = getArray(json, name, size);
return fromItem(jArray, func, array, itemSize, *size);
}
static char* getString(const cJSON* json, const char* name) {
char* p = cJSON_GetStringValue(cJSON_GetObjectItem(json, name));
char* res = calloc(1, strlen(p) + 1);
strcpy(res, p);
return res;
}
static void copyString(const cJSON* json, const char* name, char* dst) {
strcpy(dst, cJSON_GetStringValue(cJSON_GetObjectItem(json, name)));
}
static int64_t getNumber(const cJSON* json, const char* name) {
return cJSON_GetNumberValue(cJSON_GetObjectItem(json, name));
}
static const char* jkSchemaType = "Type";
static const char* jkSchemaColId = "ColId";
static const char* jkSchemaBytes = "Bytes";
// The 'name' field do not need to be serialized.
static bool schemaToJson(const void* obj, cJSON* jSchema) {
const SSlotSchema* schema = (const SSlotSchema*)obj;
bool res = cJSON_AddNumberToObject(jSchema, jkSchemaType, schema->type);
if (res) {
res = cJSON_AddNumberToObject(jSchema, jkSchemaColId, schema->colId);
}
if (res) {
res = cJSON_AddNumberToObject(jSchema, jkSchemaBytes, schema->bytes);
}
return res;
}
static bool schemaFromJson(const cJSON* json, void* obj) {
SSlotSchema* schema = (SSlotSchema*)obj;
schema->type = getNumber(json, jkSchemaType);
schema->colId = getNumber(json, jkSchemaColId);
schema->bytes = getNumber(json, jkSchemaBytes);
return true;
}
static const char* jkColumnFilterInfoLowerRelOptr = "LowerRelOptr";
static const char* jkColumnFilterInfoUpperRelOptr = "UpperRelOptr";
static const char* jkColumnFilterInfoFilterstr = "Filterstr";
static const char* jkColumnFilterInfoLowerBnd = "LowerBnd";
static const char* jkColumnFilterInfoUpperBnd = "UpperBnd";
static bool columnFilterInfoToJson(const void* obj, cJSON* jFilter) {
const SColumnFilterInfo* filter = (const SColumnFilterInfo*)obj;
bool res = cJSON_AddNumberToObject(jFilter, jkColumnFilterInfoLowerRelOptr, filter->lowerRelOptr);
if (res) {
res = cJSON_AddNumberToObject(jFilter, jkColumnFilterInfoUpperRelOptr, filter->upperRelOptr);
}
if (res) {
res = cJSON_AddNumberToObject(jFilter, jkColumnFilterInfoFilterstr, filter->filterstr);
}
if (res) {
res = cJSON_AddNumberToObject(jFilter, jkColumnFilterInfoLowerBnd, filter->lowerBndd);
}
if (res) {
res = cJSON_AddNumberToObject(jFilter, jkColumnFilterInfoUpperBnd, filter->upperBndd);
}
return res;
}
static bool columnFilterInfoFromJson(const cJSON* json, void* obj) {
SColumnFilterInfo* filter = (SColumnFilterInfo*)obj;
filter->lowerRelOptr = getNumber(json, jkColumnFilterInfoLowerRelOptr);
filter->upperRelOptr = getNumber(json, jkColumnFilterInfoUpperRelOptr);
filter->filterstr = getNumber(json, jkColumnFilterInfoFilterstr);
filter->lowerBndd = getNumber(json, jkColumnFilterInfoLowerBnd);
filter->upperBndd = getNumber(json, jkColumnFilterInfoUpperBnd);
return true;
}
static const char* jkColumnInfoColId = "ColId";
static const char* jkColumnInfoType = "Type";
static const char* jkColumnInfoBytes = "Bytes";
static const char* jkColumnInfoFilterList = "FilterList";
static bool columnInfoToJson(const void* obj, cJSON* jCol) {
const SColumnInfo* col = (const SColumnInfo*)obj;
bool res = cJSON_AddNumberToObject(jCol, jkColumnInfoColId, col->colId);
if (res) {
res = cJSON_AddNumberToObject(jCol, jkColumnInfoType, col->type);
}
if (res) {
res = cJSON_AddNumberToObject(jCol, jkColumnInfoBytes, col->bytes);
}
if (res) {
res = addRawArray(jCol, jkColumnInfoFilterList, columnFilterInfoToJson, col->flist.filterInfo, sizeof(SColumnFilterInfo), col->flist.numOfFilters);
}
return res;
}
static bool columnInfoFromJson(const cJSON* json, void* obj) {
SColumnInfo* col = (SColumnInfo*)obj;
col->colId = getNumber(json, jkColumnInfoColId);
col->type = getNumber(json, jkColumnInfoType);
col->bytes = getNumber(json, jkColumnInfoBytes);
int32_t size = 0;
bool res = fromRawArrayWithAlloc(json, jkColumnInfoFilterList, columnFilterInfoFromJson, (void**)&col->flist.filterInfo, sizeof(SColumnFilterInfo), &size);
col->flist.numOfFilters = size;
return res;
}
static const char* jkColumnTableId = "TableId";
static const char* jkColumnFlag = "Flag";
static const char* jkColumnInfo = "Info";
static bool columnToJson(const void* obj, cJSON* jCol) {
const SColumn* col = (const SColumn*)obj;
bool res = cJSON_AddNumberToObject(jCol, jkColumnTableId, col->uid);
if (res) {
res = cJSON_AddNumberToObject(jCol, jkColumnFlag, col->flag);
}
if (res) {
res = addObject(jCol, jkColumnInfo, columnInfoToJson, &col->info);
}
return res;
}
static bool columnFromJson(const cJSON* json, void* obj) {
SColumn* col = (SColumn*)obj;
col->uid = getNumber(json, jkColumnTableId);
col->flag = getNumber(json, jkColumnFlag);
return fromObject(json, jkColumnInfo, columnInfoFromJson, &col->info, true);
}
static bool exprNodeToJson(const void* obj, cJSON* jExprInfo);
static bool exprNodeFromJson(const cJSON* json, void* obj);
static const char* jkExprNodeOper = "Oper";
static const char* jkExprNodeLeft = "Left";
static const char* jkExprNodeRight = "Right";
static bool operatorToJson(const void* obj, cJSON* jOper) {
const tExprNode* exprInfo = (const tExprNode*)obj;
bool res = cJSON_AddNumberToObject(jOper, jkExprNodeOper, exprInfo->_node.optr);
if (res) {
res = addObject(jOper, jkExprNodeLeft, exprNodeToJson, exprInfo->_node.pLeft);
}
if (res) {
res = addObject(jOper, jkExprNodeRight, exprNodeToJson, exprInfo->_node.pRight);
}
return res;
}
static bool operatorFromJson(const cJSON* json, void* obj) {
tExprNode* exprInfo = (tExprNode*)obj;
exprInfo->_node.optr = getNumber(json, jkExprNodeOper);
bool res = fromObject(json, jkExprNodeLeft, exprNodeFromJson, exprInfo->_node.pLeft, false);
if (res) {
res = fromObject(json, jkExprNodeRight, exprNodeFromJson, exprInfo->_node.pRight, false);
}
return res;
}
static const char* jkFunctionName = "Name";
static const char* jkFunctionChild = "Child";
static bool functionToJson(const void* obj, cJSON* jFunc) {
const tExprNode* exprInfo = (const tExprNode*)obj;
bool res = cJSON_AddStringToObject(jFunc, jkFunctionName, exprInfo->_function.functionName);
if (res) {
res = addRawArray(jFunc, jkFunctionChild, exprNodeToJson, exprInfo->_function.pChild, sizeof(tExprNode*), exprInfo->_function.num);
}
return res;
}
static bool functionFromJson(const cJSON* json, void* obj) {
tExprNode* exprInfo = (tExprNode*)obj;
copyString(json, jkFunctionName, exprInfo->_function.functionName);
return fromRawArrayWithAlloc(json, jkFunctionChild, exprNodeFromJson, (void**)exprInfo->_function.pChild, sizeof(tExprNode*), &exprInfo->_function.num);
}
static const char* jkVariantType = "Type";
static const char* jkVariantLen = "Len";
static const char* jkVariantvalues = "values";
static const char* jkVariantValue = "Value";
static bool variantToJson(const void* obj, cJSON* jVar) {
const SVariant* var = (const SVariant*)obj;
bool res = cJSON_AddNumberToObject(jVar, jkVariantType, var->nType);
if (res) {
res = cJSON_AddNumberToObject(jVar, jkVariantLen, var->nLen);
}
if (res) {
if (0/* in */) {
res = addArray(jVar, jkVariantvalues, variantToJson, var->arr);
} else if (IS_NUMERIC_TYPE(var->nType)) {
res = cJSON_AddNumberToObject(jVar, jkVariantValue, var->d);
} else {
res = cJSON_AddStringToObject(jVar, jkVariantValue, var->pz);
}
}
return res;
}
static bool variantFromJson(const cJSON* json, void* obj) {
SVariant* var = (SVariant*)obj;
var->nType = getNumber(json, jkVariantType);
var->nLen = getNumber(json, jkVariantLen);
if (0/* in */) {
return fromArray(json, jkVariantvalues, variantFromJson, &var->arr, sizeof(SVariant));
} else if (IS_NUMERIC_TYPE(var->nType)) {
var->d = getNumber(json, jkVariantValue);
} else {
var->pz = getString(json, jkVariantValue);
}
return true;
}
static const char* jkExprNodeType = "Type";
static const char* jkExprNodeOperator = "Operator";
static const char* jkExprNodeFunction = "Function";
static const char* jkExprNodeColumn = "Column";
static const char* jkExprNodeValue = "Value";
static bool exprNodeToJson(const void* obj, cJSON* jExprInfo) {
const tExprNode* exprInfo = (const tExprNode*)obj;
bool res = cJSON_AddNumberToObject(jExprInfo, jkExprNodeType, exprInfo->nodeType);
if (res) {
switch (exprInfo->nodeType) {
case TEXPR_BINARYEXPR_NODE:
case TEXPR_UNARYEXPR_NODE:
res = addObject(jExprInfo, jkExprNodeOperator, operatorToJson, exprInfo);
break;
case TEXPR_FUNCTION_NODE:
res = addObject(jExprInfo, jkExprNodeFunction, functionToJson, exprInfo);
break;
case TEXPR_COL_NODE:
res = addObject(jExprInfo, jkExprNodeColumn, schemaToJson, exprInfo->pSchema);
break;
case TEXPR_VALUE_NODE:
res = addObject(jExprInfo, jkExprNodeValue, variantToJson, exprInfo->pVal);
break;
default:
res = false;
break;
}
}
return res;
}
static bool exprNodeFromJson(const cJSON* json, void* obj) {
tExprNode* exprInfo = (tExprNode*)obj;
exprInfo->nodeType = getNumber(json, jkExprNodeType);
switch (exprInfo->nodeType) {
case TEXPR_BINARYEXPR_NODE:
case TEXPR_UNARYEXPR_NODE:
return fromObject(json, jkExprNodeOperator, operatorFromJson, exprInfo, false);
case TEXPR_FUNCTION_NODE:
return fromObject(json, jkExprNodeFunction, functionFromJson, exprInfo, false);
case TEXPR_COL_NODE:
return fromObject(json, jkExprNodeColumn, schemaFromJson, exprInfo->pSchema, false);
case TEXPR_VALUE_NODE:
return fromObject(json, jkExprNodeValue, variantFromJson, exprInfo->pVal, false);
default:
break;
}
return false;
}
static const char* jkSqlExprSchema = "Schema";
static const char* jkSqlExprColumns = "Columns";
static const char* jkSqlExprInterBytes = "InterBytes";
static const char* jkSqlExprParams = "Params";
// token does not need to be serialized.
static bool sqlExprToJson(const void* obj, cJSON* jExpr) {
const SSqlExpr* expr = (const SSqlExpr*)obj;
bool res = addObject(jExpr, jkSqlExprSchema, schemaToJson, &expr->resSchema);
if (res) {
res = addRawArray(jExpr, jkSqlExprColumns, columnToJson, expr->pColumns, sizeof(SColumn), expr->numOfCols);
}
if (res) {
res = cJSON_AddNumberToObject(jExpr, jkSqlExprInterBytes, expr->interBytes);
}
if (res) {
res = addRawArray(jExpr, jkSqlExprParams, variantToJson, expr->param, sizeof(SVariant), expr->numOfParams);
}
return res;
}
static bool sqlExprFromJson(const cJSON* json, void* obj) {
SSqlExpr* expr = (SSqlExpr*)obj;
bool res = fromObject(json, jkSqlExprSchema, schemaFromJson, &expr->resSchema, false);
if (res) {
res = fromRawArrayWithAlloc(json, jkSqlExprColumns, columnFromJson, (void**)&expr->pColumns, sizeof(SColumn), &expr->numOfCols);
}
if (res) {
expr->interBytes = getNumber(json, jkSqlExprInterBytes);
}
if (res) {
int32_t size = 0;
res = fromRawArray(json, jkSqlExprParams, variantFromJson, expr->param, sizeof(SVariant), &size);
expr->numOfParams = size;
}
return res;
}
static const char* jkExprInfoBase = "Base";
static const char* jkExprInfoExpr = "Expr";
static bool exprInfoToJson(const void* obj, cJSON* jExprInfo) {
const SExprInfo* exprInfo = (const SExprInfo*)obj;
bool res = addObject(jExprInfo, jkExprInfoBase, sqlExprToJson, &exprInfo->base);
if (res) {
res = addObject(jExprInfo, jkExprInfoExpr, exprNodeToJson, exprInfo->pExpr);
}
return res;
}
static bool exprInfoFromJson(const cJSON* json, void* obj) {
SExprInfo* exprInfo = (SExprInfo*)obj;
bool res = fromObject(json, jkExprInfoBase, sqlExprFromJson, &exprInfo->base, true);
if (res) {
res = fromObjectWithAlloc(json, jkExprInfoExpr, exprNodeFromJson, (void**)&exprInfo->pExpr, sizeof(tExprNode), true);
}
return res;
}
static const char* jkTimeWindowStartKey = "StartKey";
static const char* jkTimeWindowEndKey = "EndKey";
static bool timeWindowToJson(const void* obj, cJSON* json) {
const STimeWindow* win = (const STimeWindow*)obj;
bool res = cJSON_AddNumberToObject(json, jkTimeWindowStartKey, win->skey);
if (res) {
res = cJSON_AddNumberToObject(json, jkTimeWindowEndKey, win->ekey);
}
return res;
}
static bool timeWindowFromJson(const cJSON* json, void* obj) {
STimeWindow* win = (STimeWindow*)obj;
win->skey = getNumber(json, jkTimeWindowStartKey);
win->ekey = getNumber(json, jkTimeWindowEndKey);
return true;
}
static const char* jkScanNodeTableId = "TableId";
static const char* jkScanNodeTableType = "TableType";
static bool scanNodeToJson(const void* obj, cJSON* json) {
const SScanPhyNode* scan = (const SScanPhyNode*)obj;
bool res = cJSON_AddNumberToObject(json, jkScanNodeTableId, scan->uid);
if (res) {
res = cJSON_AddNumberToObject(json, jkScanNodeTableType, scan->tableType);
}
return res;
}
static bool scanNodeFromJson(const cJSON* json, void* obj) {
SScanPhyNode* scan = (SScanPhyNode*)obj;
scan->uid = getNumber(json, jkScanNodeTableId);
scan->tableType = getNumber(json, jkScanNodeTableType);
return true;
}
static const char* jkTableScanNodeFlag = "Flag";
static const char* jkTableScanNodeWindow = "Window";
static const char* jkTableScanNodeTagsConditions = "TagsConditions";
static bool tableScanNodeToJson(const void* obj, cJSON* json) {
const STableScanPhyNode* scan = (const STableScanPhyNode*)obj;
bool res = scanNodeToJson(obj, json);
if (res) {
res = cJSON_AddNumberToObject(json, jkTableScanNodeFlag, scan->scanFlag);
}
if (res) {
res = addObject(json, jkTableScanNodeWindow, timeWindowToJson, &scan->window);
}
if (res) {
res = addArray(json, jkTableScanNodeTagsConditions, exprInfoToJson, scan->pTagsConditions);
}
return res;
}
static bool tableScanNodeFromJson(const cJSON* json, void* obj) {
STableScanPhyNode* scan = (STableScanPhyNode*)obj;
bool res = scanNodeFromJson(json, obj);
if (res) {
scan->scanFlag = getNumber(json, jkTableScanNodeFlag);
}
if (res) {
res = fromObject(json, jkTableScanNodeWindow, timeWindowFromJson, &scan->window, true);
}
if (res) {
res = fromArray(json, jkTableScanNodeTagsConditions, exprInfoFromJson, &scan->pTagsConditions, sizeof(SExprInfo));
}
return res;
}
static const char* jkEpAddrFqdn = "Fqdn";
static const char* jkEpAddrPort = "Port";
static bool epAddrToJson(const void* obj, cJSON* json) {
const SEpAddrMsg* ep = (const SEpAddrMsg*)obj;
bool res = cJSON_AddStringToObject(json, jkEpAddrFqdn, ep->fqdn);
if (res) {
res = cJSON_AddNumberToObject(json, jkEpAddrPort, ep->port);
}
return res;
}
static bool epAddrFromJson(const cJSON* json, void* obj) {
SEpAddrMsg* ep = (SEpAddrMsg*)obj;
copyString(json, jkEpAddrFqdn, ep->fqdn);
ep->port = getNumber(json, jkEpAddrPort);
return true;
}
static const char* jkExchangeNodeSrcTemplateId = "SrcTemplateId";
static const char* jkExchangeNodeSrcEndPoints = "SrcEndPoints";
static bool exchangeNodeToJson(const void* obj, cJSON* json) {
const SExchangePhyNode* exchange = (const SExchangePhyNode*)obj;
bool res = cJSON_AddNumberToObject(json, jkExchangeNodeSrcTemplateId, exchange->srcTemplateId);
if (res) {
res = addArray(json, jkExchangeNodeSrcEndPoints, epAddrToJson, exchange->pSrcEndPoints);
}
return res;
}
static bool exchangeNodeFromJson(const cJSON* json, void* obj) {
SExchangePhyNode* exchange = (SExchangePhyNode*)obj;
exchange->srcTemplateId = getNumber(json, jkExchangeNodeSrcTemplateId);
return fromArray(json, jkExchangeNodeSrcEndPoints, epAddrFromJson, &exchange->pSrcEndPoints, sizeof(SEpAddrMsg));
}
static bool specificPhyNodeToJson(const void* obj, cJSON* json) {
const SPhyNode* phyNode = (const SPhyNode*)obj;
switch (phyNode->info.type) {
case OP_TableScan:
case OP_DataBlocksOptScan:
case OP_TableSeqScan:
return tableScanNodeToJson(obj, json);
case OP_TagScan:
case OP_SystemTableScan:
return scanNodeToJson(obj, json);
case OP_Aggregate:
break; // todo
case OP_Project:
return true;
case OP_Groupby:
case OP_Limit:
case OP_SLimit:
case OP_TimeWindow:
case OP_SessionWindow:
case OP_StateWindow:
case OP_Fill:
case OP_MultiTableAggregate:
case OP_MultiTableTimeInterval:
case OP_Filter:
case OP_Distinct:
case OP_Join:
case OP_AllTimeWindow:
case OP_AllMultiTableTimeInterval:
case OP_Order:
break; // todo
case OP_Exchange:
return exchangeNodeToJson(obj, json);
default:
break;
}
return false;
}
static bool specificPhyNodeFromJson(const cJSON* json, void* obj) {
SPhyNode* phyNode = (SPhyNode*)obj;
switch (phyNode->info.type) {
case OP_TableScan:
case OP_DataBlocksOptScan:
case OP_TableSeqScan:
return tableScanNodeFromJson(json, obj);
case OP_TagScan:
case OP_SystemTableScan:
return scanNodeFromJson(json, obj);
case OP_Aggregate:
break; // todo
case OP_Project:
return true;
case OP_Groupby:
case OP_Limit:
case OP_SLimit:
case OP_TimeWindow:
case OP_SessionWindow:
case OP_StateWindow:
case OP_Fill:
case OP_MultiTableAggregate:
case OP_MultiTableTimeInterval:
case OP_Filter:
case OP_Distinct:
case OP_Join:
case OP_AllTimeWindow:
case OP_AllMultiTableTimeInterval:
case OP_Order:
break; // todo
case OP_Exchange:
return exchangeNodeFromJson(json, obj);
default:
break;
}
return false;
}
static const char* jkPnodeName = "Name";
static const char* jkPnodeTargets = "Targets";
static const char* jkPnodeConditions = "Conditions";
static const char* jkPnodeSchema = "Schema";
static const char* jkPnodeChildren = "Children";
// The 'pParent' field do not need to be serialized.
static bool phyNodeToJson(const void* obj, cJSON* jNode) {
const SPhyNode* phyNode = (const SPhyNode*)obj;
bool res = cJSON_AddStringToObject(jNode, jkPnodeName, phyNode->info.name);
if (res) {
res = addArray(jNode, jkPnodeTargets, exprInfoToJson, phyNode->pTargets);
}
if (res) {
res = addArray(jNode, jkPnodeConditions, exprInfoToJson, phyNode->pConditions);
}
if (res) {
res = addRawArray(jNode, jkPnodeSchema, schemaToJson, phyNode->targetSchema.pSchema, sizeof(SSlotSchema), phyNode->targetSchema.numOfCols);
}
if (res) {
res = addArray(jNode, jkPnodeChildren, phyNodeToJson, phyNode->pChildren);
}
if (res) {
res = addObject(jNode, phyNode->info.name, specificPhyNodeToJson, phyNode);
}
return res;
}
static bool phyNodeFromJson(const cJSON* json, void* obj) {
SPhyNode* node = (SPhyNode*)obj;
node->info.name = getString(json, jkPnodeName);
node->info.type = opNameToOpType(node->info.name);
bool res = fromArray(json, jkPnodeTargets, exprInfoFromJson, &node->pTargets, sizeof(SExprInfo));
if (res) {
res = fromArray(json, jkPnodeConditions, exprInfoFromJson, &node->pConditions, sizeof(SExprInfo));
}
if (res) {
res = fromRawArray(json, jkPnodeSchema, schemaFromJson, node->targetSchema.pSchema, sizeof(SSlotSchema), &node->targetSchema.numOfCols);
}
if (res) {
res = fromArray(json, jkPnodeChildren, phyNodeFromJson, &node->pChildren, sizeof(SSlotSchema));
}
if (res) {
res = fromObject(json, node->info.name, specificPhyNodeFromJson, node, true);
}
return res;
}
static const char* jkIdQueryId = "QueryId";
static const char* jkIdTemplateId = "TemplateId";
static const char* jkIdSubplanId = "SubplanId";
static bool subplanIdToJson(const void* obj, cJSON* jId) {
const SSubplanId* id = (const SSubplanId*)obj;
bool res = cJSON_AddNumberToObject(jId, jkIdQueryId, id->queryId);
if (res) {
res = cJSON_AddNumberToObject(jId, jkIdTemplateId, id->templateId);
}
if (res) {
res = cJSON_AddNumberToObject(jId, jkIdSubplanId, id->subplanId);
}
return res;
}
static bool subplanIdFromJson(const cJSON* json, void* obj) {
SSubplanId* id = (SSubplanId*)obj;
id->queryId = getNumber(json, jkIdQueryId);
id->templateId = getNumber(json, jkIdTemplateId);
id->subplanId = getNumber(json, jkIdSubplanId);
return true;
}
static const char* jkSubplanId = "Id";
static const char* jkSubplanNode = "Node";
static cJSON* subplanToJson(const SSubplan* subplan) {
cJSON* jSubplan = cJSON_CreateObject();
if (NULL == jSubplan) {
return NULL;
}
// The 'type', 'level', 'execEpSet', 'pChildern' and 'pParents' fields do not need to be serialized.
bool res = addObject(jSubplan, jkSubplanId, subplanIdToJson, &subplan->id);
if (res) {
res = addObject(jSubplan, jkSubplanNode, phyNodeToJson, subplan->pNode);
}
if (!res) {
cJSON_Delete(jSubplan);
return NULL;
}
return jSubplan;
}
static SSubplan* subplanFromJson(const cJSON* json) {
SSubplan* subplan = calloc(1, sizeof(SSubplan));
if (NULL == subplan) {
return NULL;
}
bool res = fromObject(json, jkSubplanId, subplanIdFromJson, &subplan->id, true);
if (res) {
res = fromObjectWithAlloc(json, jkSubplanNode, phyNodeFromJson, (void**)&subplan->pNode, sizeof(SPhyNode), false);
}
if (!res) {
qDestroySubplan(subplan);
return NULL;
}
return subplan;
}
int32_t subPlanToString(const SSubplan* subplan, char** str) {
cJSON* json = subplanToJson(subplan);
if (NULL == json) {
terrno = TSDB_CODE_TSC_OUT_OF_MEMORY;
return TSDB_CODE_FAILED;
}
*str = cJSON_Print(json);
return TSDB_CODE_SUCCESS;
}
int32_t stringToSubplan(const char* str, SSubplan** subplan) {
cJSON* json = cJSON_Parse(str);
if (NULL == json) {
return TSDB_CODE_FAILED;
}
*subplan = subplanFromJson(json);
return (NULL == *subplan ? TSDB_CODE_FAILED : TSDB_CODE_SUCCESS);
}
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
#include "parser.h" #include "parser.h"
#include "plannerInt.h" #include "plannerInt.h"
void qDestroySubplan(SSubplan* pSubplan) {
// todo
}
void qDestroyQueryDag(struct SQueryDag* pDag) { void qDestroyQueryDag(struct SQueryDag* pDag) {
// todo // todo
} }
...@@ -41,3 +45,15 @@ int32_t qCreateQueryDag(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet* ...@@ -41,3 +45,15 @@ int32_t qCreateQueryDag(const struct SQueryStmtInfo* pQueryInfo, struct SEpSet*
destroyQueryPlan(logicPlan); destroyQueryPlan(logicPlan);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
int32_t qSetSubplanExecutionNode(SSubplan* subplan, uint64_t templateId, SArray* eps) {
return setSubplanExecutionNode(subplan, templateId, eps);
}
int32_t qSubPlanToString(const SSubplan *subplan, char** str) {
return subPlanToString(subplan, str);
}
int32_t qStringToSubplan(const char* str, SSubplan** subplan) {
return stringToSubplan(str, subplan);
}
...@@ -8,7 +8,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) ...@@ -8,7 +8,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
ADD_EXECUTABLE(plannerTest ${SOURCE_LIST}) ADD_EXECUTABLE(plannerTest ${SOURCE_LIST})
TARGET_LINK_LIBRARIES( TARGET_LINK_LIBRARIES(
plannerTest plannerTest
PUBLIC os util common planner parser catalog transport gtest function query PUBLIC os util common planner parser catalog transport gtest function qcom
) )
TARGET_INCLUDE_DIRECTORIES( TARGET_INCLUDE_DIRECTORIES(
......
aux_source_directory(src QUERY_SRC) aux_source_directory(src QUERY_SRC)
add_library(query ${QUERY_SRC}) add_library(qcom ${QUERY_SRC})
target_include_directories( target_include_directories(
query qcom
PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/query" PUBLIC "${CMAKE_SOURCE_DIR}/include/libs/qcom"
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
) )
target_link_libraries( target_link_libraries(
query qcom
PRIVATE os util common transport PRIVATE os util transport
) )
#include "os.h"
#include "taosmsg.h"
#define VALIDNUMOFCOLS(x) ((x) >= TSDB_MIN_COLUMNS && (x) <= TSDB_MAX_COLUMNS)
#define VALIDNUMOFTAGS(x) ((x) >= 0 && (x) <= TSDB_MAX_TAGS)
static struct SSchema _s = {
.colId = TSDB_TBNAME_COLUMN_INDEX,
.type = TSDB_DATA_TYPE_BINARY,
.bytes = TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE,
.name = "tbname",
};
SSchema* tGetTbnameColumnSchema() {
return &_s;
}
static bool doValidateSchema(SSchema* pSchema, int32_t numOfCols, int32_t maxLen) {
int32_t rowLen = 0;
for (int32_t i = 0; i < numOfCols; ++i) {
// 1. valid types
if (!isValidDataType(pSchema[i].type)) {
return false;
}
// 2. valid length for each type
if (pSchema[i].type == TSDB_DATA_TYPE_BINARY) {
if (pSchema[i].bytes > TSDB_MAX_BINARY_LEN) {
return false;
}
} else if (pSchema[i].type == TSDB_DATA_TYPE_NCHAR) {
if (pSchema[i].bytes > TSDB_MAX_NCHAR_LEN) {
return false;
}
} else {
if (pSchema[i].bytes != tDataTypes[pSchema[i].type].bytes) {
return false;
}
}
// 3. valid column names
for (int32_t j = i + 1; j < numOfCols; ++j) {
if (strncasecmp(pSchema[i].name, pSchema[j].name, sizeof(pSchema[i].name) - 1) == 0) {
return false;
}
}
rowLen += pSchema[i].bytes;
}
return rowLen <= maxLen;
}
bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags) {
if (!VALIDNUMOFCOLS(numOfCols)) {
return false;
}
if (!VALIDNUMOFTAGS(numOfTags)) {
return false;
}
/* first column must be the timestamp, which is a primary key */
if (pSchema[0].type != TSDB_DATA_TYPE_TIMESTAMP) {
return false;
}
if (!doValidateSchema(pSchema, numOfCols, TSDB_MAX_BYTES_PER_ROW)) {
return false;
}
if (!doValidateSchema(&pSchema[numOfCols], numOfTags, TSDB_MAX_TAGS_LEN)) {
return false;
}
return true;
}
\ No newline at end of file
...@@ -39,7 +39,7 @@ int32_t queryBuildTableMetaReqMsg(void* input, char **msg, int32_t msgSize, int3 ...@@ -39,7 +39,7 @@ int32_t queryBuildTableMetaReqMsg(void* input, char **msg, int32_t msgSize, int3
STableInfoMsg *bMsg = (STableInfoMsg *)*msg; STableInfoMsg *bMsg = (STableInfoMsg *)*msg;
bMsg->msgHead.vgId = bInput->vgId; bMsg->vgId = bInput->vgId;
strncpy(bMsg->tableFname, bInput->tableFullName, sizeof(bMsg->tableFname)); strncpy(bMsg->tableFname, bInput->tableFullName, sizeof(bMsg->tableFname));
bMsg->tableFname[sizeof(bMsg->tableFname) - 1] = 0; bMsg->tableFname[sizeof(bMsg->tableFname) - 1] = 0;
...@@ -305,7 +305,7 @@ void msgInit() { ...@@ -305,7 +305,7 @@ void msgInit() {
tscBuildMsg[TSDB_SQL_HB] = tscBuildHeartBeatMsg; tscBuildMsg[TSDB_SQL_HB] = tscBuildHeartBeatMsg;
tscBuildMsg[TSDB_SQL_SHOW] = tscBuildShowMsg; tscBuildMsg[TSDB_SQL_SHOW] = tscBuildShowMsg;
tscBuildMsg[TSDB_SQL_RETRIEVE] = tscBuildRetrieveFromMgmtMsg; tscBuildMsg[TSDB_SQL_RETRIEVE_MNODE] = tscBuildRetrieveFromMgmtMsg;
tscBuildMsg[TSDB_SQL_KILL_QUERY] = tscBuildKillMsg; tscBuildMsg[TSDB_SQL_KILL_QUERY] = tscBuildKillMsg;
tscBuildMsg[TSDB_SQL_KILL_STREAM] = tscBuildKillMsg; tscBuildMsg[TSDB_SQL_KILL_STREAM] = tscBuildKillMsg;
tscBuildMsg[TSDB_SQL_KILL_CONNECTION] = tscBuildKillMsg; tscBuildMsg[TSDB_SQL_KILL_CONNECTION] = tscBuildKillMsg;
...@@ -323,7 +323,7 @@ void msgInit() { ...@@ -323,7 +323,7 @@ void msgInit() {
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_FUNC] = tscProcessRetrieveFuncRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE_FUNC] = tscProcessRetrieveFuncRsp;
tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp; tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp;
tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromNode; // rsp handled by same function. tscProcessMsgRsp[TSDB_SQL_RETRIEVE_MNODE] = tscProcessRetrieveRspFromNode; // rsp handled by same function.
tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp; tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp;
tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessLocalRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessLocalRetrieveRsp;
......
...@@ -9,5 +9,5 @@ target_include_directories( ...@@ -9,5 +9,5 @@ target_include_directories(
target_link_libraries( target_link_libraries(
scheduler scheduler
PRIVATE os util planner common query PRIVATE os util planner qcom common
) )
\ No newline at end of file
...@@ -16,72 +16,70 @@ ...@@ -16,72 +16,70 @@
#ifndef _TD_WAL_INT_H_ #ifndef _TD_WAL_INT_H_
#define _TD_WAL_INT_H_ #define _TD_WAL_INT_H_
#include "wal.h"
#include "compare.h" #include "compare.h"
#include "tchecksum.h" #include "tchecksum.h"
#include "wal.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
//meta section begin // meta section begin
typedef struct WalFileInfo { typedef struct WalFileInfo {
int64_t firstVer; int64_t firstVer;
int64_t lastVer; int64_t lastVer;
int64_t createTs; int64_t createTs;
int64_t closeTs; int64_t closeTs;
int64_t fileSize; int64_t fileSize;
} WalFileInfo; } SWalFileInfo;
typedef struct WalIdxEntry { typedef struct WalIdxEntry {
int64_t ver; int64_t ver;
int64_t offset; int64_t offset;
} WalIdxEntry; } SWalIdxEntry;
static inline int32_t compareWalFileInfo(const void* pLeft, const void* pRight) { static inline int32_t compareWalFileInfo(const void* pLeft, const void* pRight) {
WalFileInfo* pInfoLeft = (WalFileInfo*)pLeft; SWalFileInfo* pInfoLeft = (SWalFileInfo*)pLeft;
WalFileInfo* pInfoRight = (WalFileInfo*)pRight; SWalFileInfo* pInfoRight = (SWalFileInfo*)pRight;
return compareInt64Val(&pInfoLeft->firstVer, &pInfoRight->firstVer); return compareInt64Val(&pInfoLeft->firstVer, &pInfoRight->firstVer);
} }
static inline int64_t walGetLastFileSize(SWal* pWal) { static inline int64_t walGetLastFileSize(SWal* pWal) {
WalFileInfo* pInfo = (WalFileInfo*)taosArrayGetLast(pWal->fileInfoSet); SWalFileInfo* pInfo = (SWalFileInfo*)taosArrayGetLast(pWal->fileInfoSet);
return pInfo->fileSize; return pInfo->fileSize;
} }
static inline int64_t walGetLastFileFirstVer(SWal* pWal) { static inline int64_t walGetLastFileFirstVer(SWal* pWal) {
WalFileInfo* pInfo = (WalFileInfo*)taosArrayGetLast(pWal->fileInfoSet); SWalFileInfo* pInfo = (SWalFileInfo*)taosArrayGetLast(pWal->fileInfoSet);
return pInfo->firstVer; return pInfo->firstVer;
} }
static inline int64_t walGetCurFileFirstVer(SWal* pWal) { static inline int64_t walGetCurFileFirstVer(SWal* pWal) {
WalFileInfo* pInfo = (WalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->writeCur); SWalFileInfo* pInfo = (SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->writeCur);
return pInfo->firstVer; return pInfo->firstVer;
} }
static inline int64_t walGetCurFileLastVer(SWal* pWal) { static inline int64_t walGetCurFileLastVer(SWal* pWal) {
WalFileInfo* pInfo = (WalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->writeCur); SWalFileInfo* pInfo = (SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->writeCur);
return pInfo->firstVer; return pInfo->firstVer;
} }
static inline int64_t walGetCurFileOffset(SWal* pWal) { static inline int64_t walGetCurFileOffset(SWal* pWal) {
WalFileInfo* pInfo = (WalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->writeCur); SWalFileInfo* pInfo = (SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->writeCur);
return pInfo->fileSize; return pInfo->fileSize;
} }
static inline bool walCurFileClosed(SWal* pWal) { static inline bool walCurFileClosed(SWal* pWal) { return taosArrayGetSize(pWal->fileInfoSet) != pWal->writeCur; }
return taosArrayGetSize(pWal->fileInfoSet) != pWal->writeCur;
}
static inline WalFileInfo* walGetCurFileInfo(SWal* pWal) { static inline SWalFileInfo* walGetCurFileInfo(SWal* pWal) {
return (WalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->writeCur); return (SWalFileInfo*)taosArrayGet(pWal->fileInfoSet, pWal->writeCur);
} }
static inline int walBuildLogName(SWal*pWal, int64_t fileFirstVer, char* buf) { static inline int walBuildLogName(SWal* pWal, int64_t fileFirstVer, char* buf) {
return sprintf(buf, "%s/%020" PRId64 "." WAL_LOG_SUFFIX, pWal->path, fileFirstVer); return sprintf(buf, "%s/%020" PRId64 "." WAL_LOG_SUFFIX, pWal->path, fileFirstVer);
} }
static inline int walBuildIdxName(SWal*pWal, int64_t fileFirstVer, char* buf) { static inline int walBuildIdxName(SWal* pWal, int64_t fileFirstVer, char* buf) {
return sprintf(buf, "%s/%020" PRId64 "." WAL_INDEX_SUFFIX, pWal->path, fileFirstVer); return sprintf(buf, "%s/%020" PRId64 "." WAL_INDEX_SUFFIX, pWal->path, fileFirstVer);
} }
...@@ -93,11 +91,11 @@ static inline int walValidBodyCksum(SWalHead* pHead) { ...@@ -93,11 +91,11 @@ static inline int walValidBodyCksum(SWalHead* pHead) {
return taosCheckChecksum((uint8_t*)pHead->head.body, pHead->head.len, pHead->cksumBody); return taosCheckChecksum((uint8_t*)pHead->head.body, pHead->head.len, pHead->cksumBody);
} }
static inline int walValidCksum(SWalHead *pHead, void* body, int64_t bodyLen) { static inline int walValidCksum(SWalHead* pHead, void* body, int64_t bodyLen) {
return walValidHeadCksum(pHead) && walValidBodyCksum(pHead); return walValidHeadCksum(pHead) && walValidBodyCksum(pHead);
} }
static inline uint32_t walCalcHeadCksum(SWalHead *pHead) { static inline uint32_t walCalcHeadCksum(SWalHead* pHead) {
return taosCalcChecksum(0, (uint8_t*)&pHead->head, sizeof(SWalReadHead)); return taosCalcChecksum(0, (uint8_t*)&pHead->head, sizeof(SWalReadHead));
} }
...@@ -106,7 +104,7 @@ static inline uint32_t walCalcBodyCksum(const void* body, uint32_t len) { ...@@ -106,7 +104,7 @@ static inline uint32_t walCalcBodyCksum(const void* body, uint32_t len) {
} }
static inline int64_t walGetVerIdxOffset(SWal* pWal, int64_t ver) { static inline int64_t walGetVerIdxOffset(SWal* pWal, int64_t ver) {
return (ver - walGetCurFileFirstVer(pWal)) * sizeof(WalIdxEntry); return (ver - walGetCurFileFirstVer(pWal)) * sizeof(SWalIdxEntry);
} }
static inline void walResetVer(SWalVer* pVer) { static inline void walResetVer(SWalVer* pVer) {
...@@ -127,15 +125,15 @@ int walCheckAndRepairIdx(SWal* pWal); ...@@ -127,15 +125,15 @@ int walCheckAndRepairIdx(SWal* pWal);
char* walMetaSerialize(SWal* pWal); char* walMetaSerialize(SWal* pWal);
int walMetaDeserialize(SWal* pWal, const char* bytes); int walMetaDeserialize(SWal* pWal, const char* bytes);
//meta section end // meta section end
//seek section // seek section
int walChangeFile(SWal *pWal, int64_t ver); int walChangeFile(SWal* pWal, int64_t ver);
//seek section end // seek section end
int64_t walGetSeq(); int64_t walGetSeq();
int walSeekVer(SWal *pWal, int64_t ver); int walSeekVer(SWal* pWal, int64_t ver);
int walRoll(SWal *pWal); int walRoll(SWal* pWal);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -79,13 +79,13 @@ int walRollFileInfo(SWal* pWal) { ...@@ -79,13 +79,13 @@ int walRollFileInfo(SWal* pWal) {
SArray* pArray = pWal->fileInfoSet; SArray* pArray = pWal->fileInfoSet;
if (taosArrayGetSize(pArray) != 0) { if (taosArrayGetSize(pArray) != 0) {
WalFileInfo* pInfo = taosArrayGetLast(pArray); SWalFileInfo* pInfo = taosArrayGetLast(pArray);
pInfo->lastVer = pWal->vers.lastVer; pInfo->lastVer = pWal->vers.lastVer;
pInfo->closeTs = ts; pInfo->closeTs = ts;
} }
// TODO: change to emplace back // TODO: change to emplace back
WalFileInfo* pNewInfo = malloc(sizeof(WalFileInfo)); SWalFileInfo* pNewInfo = malloc(sizeof(SWalFileInfo));
if (pNewInfo == NULL) { if (pNewInfo == NULL) {
return -1; return -1;
} }
...@@ -122,9 +122,9 @@ char* walMetaSerialize(SWal* pWal) { ...@@ -122,9 +122,9 @@ char* walMetaSerialize(SWal* pWal) {
cJSON_AddStringToObject(pMeta, "lastVer", buf); cJSON_AddStringToObject(pMeta, "lastVer", buf);
cJSON_AddItemToObject(pRoot, "files", pFiles); cJSON_AddItemToObject(pRoot, "files", pFiles);
WalFileInfo* pData = pWal->fileInfoSet->pData; SWalFileInfo* pData = pWal->fileInfoSet->pData;
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
WalFileInfo* pInfo = &pData[i]; SWalFileInfo* pInfo = &pData[i];
cJSON_AddItemToArray(pFiles, pField = cJSON_CreateObject()); cJSON_AddItemToArray(pFiles, pField = cJSON_CreateObject());
if (pField == NULL) { if (pField == NULL) {
cJSON_Delete(pRoot); cJSON_Delete(pRoot);
...@@ -167,10 +167,10 @@ int walMetaDeserialize(SWal* pWal, const char* bytes) { ...@@ -167,10 +167,10 @@ int walMetaDeserialize(SWal* pWal, const char* bytes) {
// deserialize // deserialize
SArray* pArray = pWal->fileInfoSet; SArray* pArray = pWal->fileInfoSet;
taosArrayEnsureCap(pArray, sz); taosArrayEnsureCap(pArray, sz);
WalFileInfo* pData = pArray->pData; SWalFileInfo* pData = pArray->pData;
for (int i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
cJSON* pInfoJson = cJSON_GetArrayItem(pFiles, i); cJSON* pInfoJson = cJSON_GetArrayItem(pFiles, i);
WalFileInfo* pInfo = &pData[i]; SWalFileInfo* pInfo = &pData[i];
pField = cJSON_GetObjectItem(pInfoJson, "firstVer"); pField = cJSON_GetObjectItem(pInfoJson, "firstVer");
pInfo->firstVer = atoll(cJSON_GetStringValue(pField)); pInfo->firstVer = atoll(cJSON_GetStringValue(pField));
pField = cJSON_GetObjectItem(pInfoJson, "lastVer"); pField = cJSON_GetObjectItem(pInfoJson, "lastVer");
......
...@@ -92,7 +92,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) { ...@@ -92,7 +92,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
pWal->writeLogTfd = -1; pWal->writeLogTfd = -1;
pWal->writeIdxTfd = -1; pWal->writeIdxTfd = -1;
pWal->writeCur = -1; pWal->writeCur = -1;
pWal->fileInfoSet = taosArrayInit(8, sizeof(WalFileInfo)); pWal->fileInfoSet = taosArrayInit(8, sizeof(SWalFileInfo));
if (pWal->fileInfoSet == NULL) { if (pWal->fileInfoSet == NULL) {
wError("vgId:%d, path:%s, failed to init taosArray %s", pWal->cfg.vgId, pWal->path, strerror(errno)); wError("vgId:%d, path:%s, failed to init taosArray %s", pWal->cfg.vgId, pWal->path, strerror(errno));
free(pWal); free(pWal);
......
...@@ -52,13 +52,13 @@ static int32_t walReadSeekFilePos(SWalReadHandle *pRead, int64_t fileFirstVer, i ...@@ -52,13 +52,13 @@ static int32_t walReadSeekFilePos(SWalReadHandle *pRead, int64_t fileFirstVer, i
int64_t logTfd = pRead->readLogTfd; int64_t logTfd = pRead->readLogTfd;
// seek position // seek position
int64_t offset = (ver - fileFirstVer) * sizeof(WalIdxEntry); int64_t offset = (ver - fileFirstVer) * sizeof(SWalIdxEntry);
code = tfLseek(idxTfd, offset, SEEK_SET); code = tfLseek(idxTfd, offset, SEEK_SET);
if (code < 0) { if (code < 0) {
return -1; return -1;
} }
WalIdxEntry entry; SWalIdxEntry entry;
if (tfRead(idxTfd, &entry, sizeof(WalIdxEntry)) != sizeof(WalIdxEntry)) { if (tfRead(idxTfd, &entry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) {
return -1; return -1;
} }
// TODO:deserialize // TODO:deserialize
...@@ -105,10 +105,10 @@ static int32_t walReadSeekVer(SWalReadHandle *pRead, int64_t ver) { ...@@ -105,10 +105,10 @@ static int32_t walReadSeekVer(SWalReadHandle *pRead, int64_t ver) {
if (ver < pWal->vers.snapshotVer) { if (ver < pWal->vers.snapshotVer) {
} }
WalFileInfo tmpInfo; SWalFileInfo tmpInfo;
tmpInfo.firstVer = ver; tmpInfo.firstVer = ver;
// bsearch in fileSet // bsearch in fileSet
WalFileInfo *pRet = taosArraySearch(pWal->fileInfoSet, &tmpInfo, compareWalFileInfo, TD_LE); SWalFileInfo *pRet = taosArraySearch(pWal->fileInfoSet, &tmpInfo, compareWalFileInfo, TD_LE);
ASSERT(pRet != NULL); ASSERT(pRet != NULL);
if (pRead->curFileFirstVer != pRet->firstVer) { if (pRead->curFileFirstVer != pRet->firstVer) {
code = walReadChangeFile(pRead, pRet->firstVer); code = walReadChangeFile(pRead, pRet->firstVer);
...@@ -159,9 +159,9 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) { ...@@ -159,9 +159,9 @@ int32_t walReadWithHandle(SWalReadHandle *pRead, int64_t ver) {
return -1; return -1;
} }
/*code = walValidBodyCksum(pRead->pHead);*/
ASSERT(pRead->pHead->head.version == ver); ASSERT(pRead->pHead->head.version == ver);
code = walValidBodyCksum(pRead->pHead);
if (code != 0) { if (code != 0) {
return -1; return -1;
} }
......
...@@ -32,9 +32,9 @@ static int walSeekFilePos(SWal* pWal, int64_t ver) { ...@@ -32,9 +32,9 @@ static int walSeekFilePos(SWal* pWal, int64_t ver) {
if (code != 0) { if (code != 0) {
return -1; return -1;
} }
WalIdxEntry entry; SWalIdxEntry entry;
// TODO:deserialize // TODO:deserialize
code = tfRead(idxTfd, &entry, sizeof(WalIdxEntry)); code = tfRead(idxTfd, &entry, sizeof(SWalIdxEntry));
if (code != 0) { if (code != 0) {
return -1; return -1;
} }
...@@ -48,7 +48,7 @@ static int walSeekFilePos(SWal* pWal, int64_t ver) { ...@@ -48,7 +48,7 @@ static int walSeekFilePos(SWal* pWal, int64_t ver) {
int walChangeFileToLast(SWal* pWal) { int walChangeFileToLast(SWal* pWal) {
int64_t idxTfd, logTfd; int64_t idxTfd, logTfd;
WalFileInfo* pRet = taosArrayGetLast(pWal->fileInfoSet); SWalFileInfo* pRet = taosArrayGetLast(pWal->fileInfoSet);
ASSERT(pRet != NULL); ASSERT(pRet != NULL);
int64_t fileFirstVer = pRet->firstVer; int64_t fileFirstVer = pRet->firstVer;
...@@ -83,10 +83,10 @@ int walChangeFile(SWal* pWal, int64_t ver) { ...@@ -83,10 +83,10 @@ int walChangeFile(SWal* pWal, int64_t ver) {
// TODO // TODO
return -1; return -1;
} }
WalFileInfo tmpInfo; SWalFileInfo tmpInfo;
tmpInfo.firstVer = ver; tmpInfo.firstVer = ver;
// bsearch in fileSet // bsearch in fileSet
WalFileInfo* pRet = taosArraySearch(pWal->fileInfoSet, &tmpInfo, compareWalFileInfo, TD_LE); SWalFileInfo* pRet = taosArraySearch(pWal->fileInfoSet, &tmpInfo, compareWalFileInfo, TD_LE);
ASSERT(pRet != NULL); ASSERT(pRet != NULL);
int64_t fileFirstVer = pRet->firstVer; int64_t fileFirstVer = pRet->firstVer;
// closed // closed
......
...@@ -56,9 +56,9 @@ int32_t walRollback(SWal *pWal, int64_t ver) { ...@@ -56,9 +56,9 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
// delete files // delete files
int fileSetSize = taosArrayGetSize(pWal->fileInfoSet); int fileSetSize = taosArrayGetSize(pWal->fileInfoSet);
for (int i = pWal->writeCur; i < fileSetSize; i++) { for (int i = pWal->writeCur; i < fileSetSize; i++) {
walBuildLogName(pWal, ((WalFileInfo *)taosArrayGet(pWal->fileInfoSet, i))->firstVer, fnameStr); walBuildLogName(pWal, ((SWalFileInfo *)taosArrayGet(pWal->fileInfoSet, i))->firstVer, fnameStr);
remove(fnameStr); remove(fnameStr);
walBuildIdxName(pWal, ((WalFileInfo *)taosArrayGet(pWal->fileInfoSet, i))->firstVer, fnameStr); walBuildIdxName(pWal, ((SWalFileInfo *)taosArrayGet(pWal->fileInfoSet, i))->firstVer, fnameStr);
remove(fnameStr); remove(fnameStr);
} }
// pop from fileInfoSet // pop from fileInfoSet
...@@ -81,8 +81,8 @@ int32_t walRollback(SWal *pWal, int64_t ver) { ...@@ -81,8 +81,8 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
} }
// read idx file and get log file pos // read idx file and get log file pos
// TODO:change to deserialize function // TODO:change to deserialize function
WalIdxEntry entry; SWalIdxEntry entry;
if (tfRead(idxTfd, &entry, sizeof(WalIdxEntry)) != sizeof(WalIdxEntry)) { if (tfRead(idxTfd, &entry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) {
pthread_mutex_unlock(&pWal->mutex); pthread_mutex_unlock(&pWal->mutex);
return -1; return -1;
} }
...@@ -128,8 +128,8 @@ int32_t walRollback(SWal *pWal, int64_t ver) { ...@@ -128,8 +128,8 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
return -1; return -1;
} }
pWal->vers.lastVer = ver - 1; pWal->vers.lastVer = ver - 1;
((WalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->lastVer = ver - 1; ((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->lastVer = ver - 1;
((WalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->fileSize = entry.offset; ((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->fileSize = entry.offset;
// unlock // unlock
pthread_mutex_unlock(&pWal->mutex); pthread_mutex_unlock(&pWal->mutex);
...@@ -155,15 +155,15 @@ int32_t walEndSnapshot(SWal *pWal) { ...@@ -155,15 +155,15 @@ int32_t walEndSnapshot(SWal *pWal) {
int deleteCnt = 0; int deleteCnt = 0;
int64_t newTotSize = pWal->totSize; int64_t newTotSize = pWal->totSize;
WalFileInfo tmp; SWalFileInfo tmp;
tmp.firstVer = ver; tmp.firstVer = ver;
// find files safe to delete // find files safe to delete
WalFileInfo *pInfo = taosArraySearch(pWal->fileInfoSet, &tmp, compareWalFileInfo, TD_LE); SWalFileInfo *pInfo = taosArraySearch(pWal->fileInfoSet, &tmp, compareWalFileInfo, TD_LE);
if (ver >= pInfo->lastVer) { if (ver >= pInfo->lastVer) {
pInfo++; pInfo++;
} }
// iterate files, until the searched result // iterate files, until the searched result
for (WalFileInfo *iter = pWal->fileInfoSet->pData; iter < pInfo; iter++) { for (SWalFileInfo *iter = pWal->fileInfoSet->pData; iter < pInfo; iter++) {
if (pWal->totSize > pWal->cfg.retentionSize || iter->closeTs + pWal->cfg.retentionPeriod > ts) { if (pWal->totSize > pWal->cfg.retentionSize || iter->closeTs + pWal->cfg.retentionPeriod > ts) {
// delete according to file size or close time // delete according to file size or close time
deleteCnt++; deleteCnt++;
...@@ -173,7 +173,7 @@ int32_t walEndSnapshot(SWal *pWal) { ...@@ -173,7 +173,7 @@ int32_t walEndSnapshot(SWal *pWal) {
char fnameStr[WAL_FILE_LEN]; char fnameStr[WAL_FILE_LEN];
// remove file // remove file
for (int i = 0; i < deleteCnt; i++) { for (int i = 0; i < deleteCnt; i++) {
WalFileInfo *pInfo = taosArrayGet(pWal->fileInfoSet, i); SWalFileInfo *pInfo = taosArrayGet(pWal->fileInfoSet, i);
walBuildLogName(pWal, pInfo->firstVer, fnameStr); walBuildLogName(pWal, pInfo->firstVer, fnameStr);
remove(fnameStr); remove(fnameStr);
walBuildIdxName(pWal, pInfo->firstVer, fnameStr); walBuildIdxName(pWal, pInfo->firstVer, fnameStr);
...@@ -186,7 +186,7 @@ int32_t walEndSnapshot(SWal *pWal) { ...@@ -186,7 +186,7 @@ int32_t walEndSnapshot(SWal *pWal) {
pWal->writeCur = -1; pWal->writeCur = -1;
pWal->vers.firstVer = -1; pWal->vers.firstVer = -1;
} else { } else {
pWal->vers.firstVer = ((WalFileInfo *)taosArrayGet(pWal->fileInfoSet, 0))->firstVer; pWal->vers.firstVer = ((SWalFileInfo *)taosArrayGet(pWal->fileInfoSet, 0))->firstVer;
} }
pWal->writeCur = taosArrayGetSize(pWal->fileInfoSet) - 1; pWal->writeCur = taosArrayGetSize(pWal->fileInfoSet) - 1;
; ;
...@@ -248,9 +248,9 @@ int walRoll(SWal *pWal) { ...@@ -248,9 +248,9 @@ int walRoll(SWal *pWal) {
} }
static int walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) { static int walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) {
WalIdxEntry entry = {.ver = ver, .offset = offset}; SWalIdxEntry entry = {.ver = ver, .offset = offset};
int size = tfWrite(pWal->writeIdxTfd, &entry, sizeof(WalIdxEntry)); int size = tfWrite(pWal->writeIdxTfd, &entry, sizeof(SWalIdxEntry));
if (size != sizeof(WalIdxEntry)) { if (size != sizeof(SWalIdxEntry)) {
// TODO truncate // TODO truncate
return -1; return -1;
} }
......
...@@ -1120,11 +1120,11 @@ SysNameInfo taosGetSysNameInfo() { ...@@ -1120,11 +1120,11 @@ SysNameInfo taosGetSysNameInfo() {
struct utsname uts; struct utsname uts;
if (!uname(&uts)) { if (!uname(&uts)) {
info.sysname = strdup(uts.sysname); tstrncpy(info.sysname, uts.sysname, sizeof(info.sysname));
info.nodename = strdup(uts.nodename); tstrncpy(info.nodename, uts.nodename, sizeof(info.nodename));
info.release = strdup(uts.release); tstrncpy(info.release, uts.release, sizeof(info.release));
info.version = strdup(uts.version); tstrncpy(info.version, uts.version, sizeof(info.version));
info.machine = strdup(uts.machine); tstrncpy(info.machine, uts.machine, sizeof(info.machine));
} }
return info; return info;
......
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/version.c.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/version.c")
aux_source_directory(src UTIL_SRC) aux_source_directory(src UTIL_SRC)
add_library(util STATIC ${UTIL_SRC}) add_library(util STATIC ${UTIL_SRC})
target_include_directories( target_include_directories(
...@@ -12,5 +13,3 @@ target_link_libraries( ...@@ -12,5 +13,3 @@ target_link_libraries(
PUBLIC lz4_static PUBLIC lz4_static
PUBLIC api PUBLIC api
) )
\ No newline at end of file
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/src/version.c.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/version.c")
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "mallocator.h" #include "mallocator.h"
/* ------------------------ HEAP ALLOCATOR ------------------------ */ /* ------------------------ HEAP ALLOCATOR ------------------------ */
#if 0
typedef struct { typedef struct {
size_t tusage; size_t tusage;
} SHeapAllocator; } SHeapAllocator;
...@@ -105,3 +106,4 @@ static size_t haUsage(SMemAllocator *pma) { return ((SHeapAllocator *)(pma->impl ...@@ -105,3 +106,4 @@ static size_t haUsage(SMemAllocator *pma) { return ((SHeapAllocator *)(pma->impl
typedef struct { typedef struct {
size_t usage; size_t usage;
} SArenaAllocator; } SArenaAllocator;
#endif
\ No newline at end of file
...@@ -217,22 +217,20 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_EXIST, "VGroup does not exist ...@@ -217,22 +217,20 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_EXIST, "VGroup does not exist
// mnode-stable // mnode-stable
TAOS_DEFINE_ERROR(TSDB_CODE_MND_STB_ALREADY_EXIST, "Stable already exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_STB_ALREADY_EXIST, "Stable already exists")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_ID, "Table name too long") TAOS_DEFINE_ERROR(TSDB_CODE_MND_STB_NOT_EXIST, "Stable not exist")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_NAME, "Table does not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_STBS, "Too many stables")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_TYPE, "Invalid table type in tsdb") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STB, "Invalid stable name")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STB_OPTION, "Invalid stable options")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_STB_OPTION_UNCHNAGED, "Stable options not changed")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TAGS, "Too many tags") TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TAGS, "Too many tags")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_COLUMNS, "Too many columns")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_TIMESERIES, "Too many time series")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NOT_SUPER_TABLE, "Not super table")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_COL_NAME_TOO_LONG, "Tag name too long")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_ALREAY_EXIST, "Tag already exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_ALREAY_EXIST, "Tag already exists")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_NOT_EXIST, "Tag does not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_TAG_NOT_EXIST, "Tag does not exist")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_ALREAY_EXIST, "Field already exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_COLUMNS, "Too many columns")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_NOT_EXIST, "Field does not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_COLUMN_ALREAY_EXIST, "Column already exists")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_STABLE_NAME, "Super table does not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_COLUMN_NOT_EXIST, "Column does not exist")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG, "Invalid create table message")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_EXCEED_MAX_ROW_BYTES, "Exceed max row bytes") TAOS_DEFINE_ERROR(TSDB_CODE_MND_EXCEED_MAX_ROW_BYTES, "Exceed max row bytes")
// mnode-func
TAOS_DEFINE_ERROR(TSDB_CODE_MND_FUNC_ALREADY_EXIST, "Func already exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_FUNC_ALREADY_EXIST, "Func already exists")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_FUNC_NOT_EXIST, "Func not exists") TAOS_DEFINE_ERROR(TSDB_CODE_MND_FUNC_NOT_EXIST, "Func not exists")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_FUNC, "Invalid func") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_FUNC, "Invalid func")
...@@ -241,9 +239,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_FUNC_COMMENT, "Invalid func comment" ...@@ -241,9 +239,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_FUNC_COMMENT, "Invalid func comment"
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_FUNC_CODE, "Invalid func code") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_FUNC_CODE, "Invalid func code")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_FUNC_BUFSIZE, "Invalid func bufSize") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_FUNC_BUFSIZE, "Invalid func bufSize")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TAG_LENGTH, "invalid tag length")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_COLUMN_LENGTH, "invalid column length")
// dnode // dnode
TAOS_DEFINE_ERROR(TSDB_CODE_DND_ACTION_IN_PROGRESS, "Action in progress") TAOS_DEFINE_ERROR(TSDB_CODE_DND_ACTION_IN_PROGRESS, "Action in progress")
TAOS_DEFINE_ERROR(TSDB_CODE_DND_EXITING, "Dnode is exiting") TAOS_DEFINE_ERROR(TSDB_CODE_DND_EXITING, "Dnode is exiting")
......
...@@ -17,9 +17,8 @@ ...@@ -17,9 +17,8 @@
#include "os.h" #include "os.h"
void tdListInit(SList *list, int eleSize) { void tdListInit(SList *list, int eleSize) {
list->eleSize = eleSize; TD_DLIST_INIT(list);
list->numOfEles = 0; listEleSize(list) = eleSize;
list->head = list->tail = NULL;
} }
SList *tdListNew(int eleSize) { SList *tdListNew(int eleSize) {
...@@ -31,14 +30,11 @@ SList *tdListNew(int eleSize) { ...@@ -31,14 +30,11 @@ SList *tdListNew(int eleSize) {
} }
void tdListEmpty(SList *list) { void tdListEmpty(SList *list) {
SListNode *node = list->head; SListNode *node;
while (node) { while ((node = TD_DLIST_HEAD(list)) != NULL) {
list->head = node->next; TD_DLIST_POP(list, node);
free(node); free(node);
node = list->head;
} }
list->head = list->tail = 0;
list->numOfEles = 0;
} }
void *tdListFree(SList *list) { void *tdListFree(SList *list) {
...@@ -50,40 +46,16 @@ void *tdListFree(SList *list) { ...@@ -50,40 +46,16 @@ void *tdListFree(SList *list) {
return NULL; return NULL;
} }
void tdListPrependNode(SList *list, SListNode *node) { void tdListPrependNode(SList *list, SListNode *node) { TD_DLIST_PREPEND(list, node); }
if (list->head == NULL) {
list->head = node;
list->tail = node;
} else {
node->next = list->head;
node->prev = NULL;
list->head->prev = node;
list->head = node;
}
list->numOfEles++;
}
void tdListAppendNode(SList *list, SListNode *node) { void tdListAppendNode(SList *list, SListNode *node) { TD_DLIST_APPEND(list, node); }
if (list->head == NULL) {
list->head = node;
list->tail = node;
} else {
node->prev = list->tail;
node->next = NULL;
list->tail->next = node;
list->tail = node;
}
list->numOfEles++;
}
int tdListPrepend(SList *list, void *data) { int tdListPrepend(SList *list, void *data) {
SListNode *node = (SListNode *)malloc(sizeof(SListNode) + list->eleSize); SListNode *node = (SListNode *)malloc(sizeof(SListNode) + list->eleSize);
if (node == NULL) return -1; if (node == NULL) return -1;
node->next = node->prev = NULL;
memcpy((void *)(node->data), data, list->eleSize); memcpy((void *)(node->data), data, list->eleSize);
tdListPrependNode(list, node); TD_DLIST_PREPEND(list, node);
return 0; return 0;
} }
...@@ -93,73 +65,40 @@ int tdListAppend(SList *list, void *data) { ...@@ -93,73 +65,40 @@ int tdListAppend(SList *list, void *data) {
if (node == NULL) return -1; if (node == NULL) return -1;
memcpy((void *)(node->data), data, list->eleSize); memcpy((void *)(node->data), data, list->eleSize);
tdListAppendNode(list, node); TD_DLIST_APPEND(list, node);
return 0; return 0;
} }
SListNode *tdListPopHead(SList *list) { SListNode *tdListPopHead(SList *list) {
if (list->head == NULL) return NULL; SListNode *node;
SListNode *node = list->head;
if (node->next == NULL) { node = TD_DLIST_HEAD(list);
list->head = NULL;
list->tail = NULL; if (node) {
} else { TD_DLIST_POP(list, node);
list->head = node->next;
} }
list->numOfEles--;
node->next = NULL;
node->prev = NULL;
return node; return node;
} }
SListNode *tdListPopTail(SList *list) { SListNode *tdListPopTail(SList *list) {
if (list->tail == NULL) return NULL; SListNode *node;
SListNode *node = list->tail;
if (node->prev == NULL) {
list->head = NULL;
list->tail = NULL;
} else {
list->tail = node->prev;
}
list->numOfEles--;
node->next = node->prev = NULL;
return node;
}
SListNode *tdListGetHead(SList *list) { node = TD_DLIST_TAIL(list);
if (list == NULL || list->numOfEles == 0) { if (node) {
return NULL; TD_DLIST_POP(list, node);
} }
return list->head; return node;
} }
SListNode *tsListGetTail(SList *list) { SListNode *tdListGetHead(SList *list) { return TD_DLIST_HEAD(list); }
if (list == NULL || list->numOfEles == 0) {
return NULL;
}
return list->tail; SListNode *tsListGetTail(SList *list) { return TD_DLIST_TAIL(list); }
}
SListNode *tdListPopNode(SList *list, SListNode *node) { SListNode *tdListPopNode(SList *list, SListNode *node) {
if (list->head == node) { TD_DLIST_POP(list, node);
list->head = node->next;
}
if (list->tail == node) {
list->tail = node->prev;
}
if (node->prev != NULL) {
node->prev->next = node->next;
}
if (node->next != NULL) {
node->next->prev = node->prev;
}
list->numOfEles--;
node->next = node->prev = NULL;
return node; return node;
} }
...@@ -174,19 +113,19 @@ void tdListMove(SList *src, SList *dst) { ...@@ -174,19 +113,19 @@ void tdListMove(SList *src, SList *dst) {
void tdListDiscard(SList *list) { void tdListDiscard(SList *list) {
if (list) { if (list) {
list->head = list->tail = NULL; listHead(list) = listTail(list) = NULL;
list->numOfEles = 0; listNEles(list) = 0;
} }
} }
void tdListNodeGetData(SList *list, SListNode *node, void *target) { memcpy(target, node->data, list->eleSize); } void tdListNodeGetData(SList *list, SListNode *node, void *target) { memcpy(target, node->data, listEleSize(list)); }
void tdListInitIter(SList *list, SListIter *pIter, TD_LIST_DIRECTION_T direction) { void tdListInitIter(SList *list, SListIter *pIter, TD_LIST_DIRECTION_T direction) {
pIter->direction = direction; pIter->direction = direction;
if (direction == TD_LIST_FORWARD) { if (direction == TD_LIST_FORWARD) {
pIter->next = list->head; pIter->next = listHead(list);
} else { } else {
pIter->next = list->tail; pIter->next = listTail(list);
} }
} }
...@@ -194,9 +133,9 @@ SListNode *tdListNext(SListIter *pIter) { ...@@ -194,9 +133,9 @@ SListNode *tdListNext(SListIter *pIter) {
SListNode *node = pIter->next; SListNode *node = pIter->next;
if (node == NULL) return NULL; if (node == NULL) return NULL;
if (pIter->direction == TD_LIST_FORWARD) { if (pIter->direction == TD_LIST_FORWARD) {
pIter->next = node->next; pIter->next = TD_DLIST_NODE_NEXT(node);
} else { } else {
pIter->next = node->prev; pIter->next = TD_DLIST_NODE_PREV(node);
} }
return node; return node;
......
...@@ -183,7 +183,7 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo ...@@ -183,7 +183,7 @@ static void tscProcessAsyncRetrieveImpl(void *param, TAOS_RES *tres, int numOfRo
pSql->fp = fp; pSql->fp = fp;
if (pCmd->command != TSDB_SQL_RETRIEVE_GLOBALMERGE && pCmd->command < TSDB_SQL_LOCAL) { if (pCmd->command != TSDB_SQL_RETRIEVE_GLOBALMERGE && pCmd->command < TSDB_SQL_LOCAL) {
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE_MNODE : TSDB_SQL_FETCH;
} }
if (pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE) { if (pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE) {
...@@ -265,7 +265,7 @@ void taos_fetch_rows_a(TAOS_RES *tres, __async_cb_func_t fp, void *param) { ...@@ -265,7 +265,7 @@ void taos_fetch_rows_a(TAOS_RES *tres, __async_cb_func_t fp, void *param) {
} }
return; return;
} else if (pCmd->command == TSDB_SQL_RETRIEVE || pCmd->command == TSDB_SQL_RETRIEVE_GLOBALMERGE) { } else if (pCmd->command == TSDB_SQL_RETRIEVE_MNODE || pCmd->command == TSDB_SQL_RETRIEVE_GLOBALMERGE) {
// in case of show command, return no data // in case of show command, return no data
(*pSql->fetchFp)(param, pSql, 0); (*pSql->fetchFp)(param, pSql, 0);
} else { } else {
...@@ -273,7 +273,7 @@ void taos_fetch_rows_a(TAOS_RES *tres, __async_cb_func_t fp, void *param) { ...@@ -273,7 +273,7 @@ void taos_fetch_rows_a(TAOS_RES *tres, __async_cb_func_t fp, void *param) {
} }
} else { // current query is not completed, continue retrieve from node } else { // current query is not completed, continue retrieve from node
if (pCmd->command != TSDB_SQL_RETRIEVE_GLOBALMERGE && pCmd->command < TSDB_SQL_LOCAL) { if (pCmd->command != TSDB_SQL_RETRIEVE_GLOBALMERGE && pCmd->command < TSDB_SQL_LOCAL) {
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE_MNODE : TSDB_SQL_FETCH;
} }
SQueryInfo* pQueryInfo1 = tscGetQueryInfo(&pSql->cmd); SQueryInfo* pQueryInfo1 = tscGetQueryInfo(&pSql->cmd);
......
...@@ -322,7 +322,7 @@ TAOS_ROW tscFetchRow(void *param) { ...@@ -322,7 +322,7 @@ TAOS_ROW tscFetchRow(void *param) {
// current data set are exhausted, fetch more data from node // current data set are exhausted, fetch more data from node
if (pRes->row >= pRes->numOfRows && (pRes->completed != true || hasMoreVnodesToTry(pSql) || hasMoreClauseToTry(pSql)) && if (pRes->row >= pRes->numOfRows && (pRes->completed != true || hasMoreVnodesToTry(pSql) || hasMoreClauseToTry(pSql)) &&
(pCmd->command == TSDB_SQL_RETRIEVE || (pCmd->command == TSDB_SQL_RETRIEVE_MNODE ||
pCmd->command == TSDB_SQL_RETRIEVE_GLOBALMERGE || pCmd->command == TSDB_SQL_RETRIEVE_GLOBALMERGE ||
pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE || pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE ||
pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_FETCH ||
......
...@@ -539,7 +539,7 @@ int doBuildAndSendMsg(SSqlObj *pSql) { ...@@ -539,7 +539,7 @@ int doBuildAndSendMsg(SSqlObj *pSql) {
if (pCmd->command == TSDB_SQL_SELECT || if (pCmd->command == TSDB_SQL_SELECT ||
pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_FETCH ||
pCmd->command == TSDB_SQL_RETRIEVE || pCmd->command == TSDB_SQL_RETRIEVE_MNODE ||
pCmd->command == TSDB_SQL_INSERT || pCmd->command == TSDB_SQL_INSERT ||
pCmd->command == TSDB_SQL_CONNECT || pCmd->command == TSDB_SQL_CONNECT ||
pCmd->command == TSDB_SQL_HB || pCmd->command == TSDB_SQL_HB ||
...@@ -2749,7 +2749,7 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) { ...@@ -2749,7 +2749,7 @@ int tscProcessRetrieveRspFromNode(SSqlObj *pSql) {
} }
STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); STableMetaInfo *pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
if ((pCmd->command == TSDB_SQL_RETRIEVE) || if ((pCmd->command == TSDB_SQL_RETRIEVE_MNODE) ||
((UTIL_TABLE_IS_CHILD_TABLE(pTableMetaInfo) || UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) && ((UTIL_TABLE_IS_CHILD_TABLE(pTableMetaInfo) || UTIL_TABLE_IS_NORMAL_TABLE(pTableMetaInfo)) &&
!TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_SUBQUERY)) || !TSDB_QUERY_HAS_TYPE(pQueryInfo->type, TSDB_QUERY_TYPE_SUBQUERY)) ||
(tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) && (tscNonOrderedProjectionQueryOnSTable(pQueryInfo, 0) &&
...@@ -3174,7 +3174,7 @@ void tscInitMsgsFp() { ...@@ -3174,7 +3174,7 @@ void tscInitMsgsFp() {
tscBuildMsg[TSDB_SQL_HB] = tscBuildHeartBeatMsg; tscBuildMsg[TSDB_SQL_HB] = tscBuildHeartBeatMsg;
tscBuildMsg[TSDB_SQL_SHOW] = tscBuildShowMsg; tscBuildMsg[TSDB_SQL_SHOW] = tscBuildShowMsg;
tscBuildMsg[TSDB_SQL_RETRIEVE] = tscBuildRetrieveFromMgmtMsg; tscBuildMsg[TSDB_SQL_RETRIEVE_MNODE] = tscBuildRetrieveFromMgmtMsg;
tscBuildMsg[TSDB_SQL_KILL_QUERY] = tscBuildKillMsg; tscBuildMsg[TSDB_SQL_KILL_QUERY] = tscBuildKillMsg;
tscBuildMsg[TSDB_SQL_KILL_STREAM] = tscBuildKillMsg; tscBuildMsg[TSDB_SQL_KILL_STREAM] = tscBuildKillMsg;
tscBuildMsg[TSDB_SQL_KILL_CONNECTION] = tscBuildKillMsg; tscBuildMsg[TSDB_SQL_KILL_CONNECTION] = tscBuildKillMsg;
...@@ -3192,7 +3192,7 @@ void tscInitMsgsFp() { ...@@ -3192,7 +3192,7 @@ void tscInitMsgsFp() {
tscProcessMsgRsp[TSDB_SQL_RETRIEVE_FUNC] = tscProcessRetrieveFuncRsp; tscProcessMsgRsp[TSDB_SQL_RETRIEVE_FUNC] = tscProcessRetrieveFuncRsp;
tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp; tscProcessMsgRsp[TSDB_SQL_SHOW] = tscProcessShowRsp;
tscProcessMsgRsp[TSDB_SQL_RETRIEVE] = tscProcessRetrieveRspFromNode; // rsp handled by same function. tscProcessMsgRsp[TSDB_SQL_RETRIEVE_MNODE] = tscProcessRetrieveRspFromNode; // rsp handled by same function.
tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp; tscProcessMsgRsp[TSDB_SQL_DESCRIBE_TABLE] = tscProcessDescribeTableRsp;
tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessLocalRetrieveRsp; tscProcessMsgRsp[TSDB_SQL_CURRENT_DB] = tscProcessLocalRetrieveRsp;
...@@ -3214,7 +3214,7 @@ void tscInitMsgsFp() { ...@@ -3214,7 +3214,7 @@ void tscInitMsgsFp() {
tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_DATABASE] = tscProcessShowCreateRsp; tscProcessMsgRsp[TSDB_SQL_SHOW_CREATE_DATABASE] = tscProcessShowCreateRsp;
tscKeepConn[TSDB_SQL_SHOW] = 1; tscKeepConn[TSDB_SQL_SHOW] = 1;
tscKeepConn[TSDB_SQL_RETRIEVE] = 1; tscKeepConn[TSDB_SQL_RETRIEVE_MNODE] = 1;
tscKeepConn[TSDB_SQL_SELECT] = 1; tscKeepConn[TSDB_SQL_SELECT] = 1;
tscKeepConn[TSDB_SQL_FETCH] = 1; tscKeepConn[TSDB_SQL_FETCH] = 1;
tscKeepConn[TSDB_SQL_HB] = 1; tscKeepConn[TSDB_SQL_HB] = 1;
......
...@@ -460,7 +460,7 @@ static bool needToFetchNewBlock(SSqlObj* pSql) { ...@@ -460,7 +460,7 @@ static bool needToFetchNewBlock(SSqlObj* pSql) {
SSqlCmd *pCmd = &pSql->cmd; SSqlCmd *pCmd = &pSql->cmd;
return (pRes->completed != true || hasMoreVnodesToTry(pSql) || hasMoreClauseToTry(pSql)) && return (pRes->completed != true || hasMoreVnodesToTry(pSql) || hasMoreClauseToTry(pSql)) &&
(pCmd->command == TSDB_SQL_RETRIEVE || (pCmd->command == TSDB_SQL_RETRIEVE_MNODE ||
pCmd->command == TSDB_SQL_RETRIEVE_GLOBALMERGE || pCmd->command == TSDB_SQL_RETRIEVE_GLOBALMERGE ||
pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE || pCmd->command == TSDB_SQL_TABLE_JOIN_RETRIEVE ||
pCmd->command == TSDB_SQL_FETCH || pCmd->command == TSDB_SQL_FETCH ||
...@@ -582,10 +582,10 @@ static bool tscKillQueryInDnode(SSqlObj* pSql) { ...@@ -582,10 +582,10 @@ static bool tscKillQueryInDnode(SSqlObj* pSql) {
if (pRes->code == TSDB_CODE_SUCCESS && pRes->completed == false && pSql->pStream == NULL && (pTableMetaInfo->pTableMeta != NULL) && if (pRes->code == TSDB_CODE_SUCCESS && pRes->completed == false && pSql->pStream == NULL && (pTableMetaInfo->pTableMeta != NULL) &&
(cmd == TSDB_SQL_SELECT || (cmd == TSDB_SQL_SELECT ||
cmd == TSDB_SQL_SHOW || cmd == TSDB_SQL_SHOW ||
cmd == TSDB_SQL_RETRIEVE || cmd == TSDB_SQL_RETRIEVE_MNODE ||
cmd == TSDB_SQL_FETCH)) { cmd == TSDB_SQL_FETCH)) {
pQueryInfo->type = TSDB_QUERY_TYPE_FREE_RESOURCE; pQueryInfo->type = TSDB_QUERY_TYPE_FREE_RESOURCE;
pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; pCmd->command = (pCmd->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE_MNODE : TSDB_SQL_FETCH;
tscDebug("0x%"PRIx64" send msg to dnode to free qhandle ASAP before free sqlObj, command:%s", pSql->self, sqlCmd[pCmd->command]); tscDebug("0x%"PRIx64" send msg to dnode to free qhandle ASAP before free sqlObj, command:%s", pSql->self, sqlCmd[pCmd->command]);
tscBuildAndSendRequest(pSql, NULL); tscBuildAndSendRequest(pSql, NULL);
......
...@@ -1670,7 +1670,7 @@ void tscFetchDatablockForSubquery(SSqlObj* pSql) { ...@@ -1670,7 +1670,7 @@ void tscFetchDatablockForSubquery(SSqlObj* pSql) {
pSql1->fp = joinRetrieveFinalResCallback; pSql1->fp = joinRetrieveFinalResCallback;
if (pCmd1->command < TSDB_SQL_LOCAL) { if (pCmd1->command < TSDB_SQL_LOCAL) {
pCmd1->command = (pCmd1->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE : TSDB_SQL_FETCH; pCmd1->command = (pCmd1->command > TSDB_SQL_MGMT) ? TSDB_SQL_RETRIEVE_MNODE : TSDB_SQL_FETCH;
} }
tscBuildAndSendRequest(pSql1, NULL); tscBuildAndSendRequest(pSql1, NULL);
......
CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20)
PROJECT(TDengine)
ADD_SUBDIRECTORY(shell)
ADD_SUBDIRECTORY(taosdemo)
ADD_SUBDIRECTORY(taosdump)
ADD_SUBDIRECTORY(taospack)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20)
PROJECT(TDengine)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc)
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc)
INCLUDE_DIRECTORIES(inc)
IF (TD_LINUX)
AUX_SOURCE_DIRECTORY(./src SRC)
LIST(REMOVE_ITEM SRC ./src/shellWindows.c)
LIST(REMOVE_ITEM SRC ./src/shellDarwin.c)
ADD_EXECUTABLE(shell ${SRC})
IF (TD_LINUX_64 AND JEMALLOC_ENABLED)
ADD_DEFINITIONS(-DTD_JEMALLOC_ENABLED -I${CMAKE_BINARY_DIR}/build/include -L${CMAKE_BINARY_DIR}/build/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/build/lib -ljemalloc)
SET(LINK_JEMALLOC "-L${CMAKE_BINARY_DIR}/build/lib -ljemalloc")
ELSE ()
SET(LINK_JEMALLOC "")
ENDIF ()
IF (TD_SOMODE_STATIC)
TARGET_LINK_LIBRARIES(shell taos_static lua ${LINK_JEMALLOC})
ELSE ()
TARGET_LINK_LIBRARIES(shell taos lua ${LINK_JEMALLOC})
ENDIF ()
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos)
ELSEIF (TD_WINDOWS)
LIST(APPEND SRC ./src/shellEngine.c)
LIST(APPEND SRC ./src/shellMain.c)
LIST(APPEND SRC ./src/shellWindows.c)
ADD_EXECUTABLE(shell ${SRC})
TARGET_LINK_LIBRARIES(shell taos_static)
IF (TD_POWER)
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME power)
ELSE ()
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos)
ENDIF ()
ELSEIF (TD_DARWIN)
LIST(APPEND SRC ./src/shellEngine.c)
LIST(APPEND SRC ./src/shellMain.c)
LIST(APPEND SRC ./src/shellDarwin.c)
LIST(APPEND SRC ./src/shellCommand.c)
LIST(APPEND SRC ./src/shellImport.c)
LIST(APPEND SRC ./src/shellCheck.c)
ADD_EXECUTABLE(shell ${SRC})
# linking with dylib
TARGET_LINK_LIBRARIES(shell taos)
# linking taos statically
# TARGET_LINK_LIBRARIES(shell taos_static)
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos)
ENDIF ()
# generate debug version: #ADD_SUBDIRECTORY(examples/c)
# mkdir debug; cd debug; cmake -DCMAKE_BUILD_TYPE=Debug ..
# generate release version:
# mkdir release; cd release; cmake -DCMAKE_BUILD_TYPE=Release ..
CMAKE_MINIMUM_REQUIRED(VERSION 2.8...3.20)
PROJECT(TDengine)
SET(CMAKE_C_STANDARD 11)
SET(CMAKE_VERBOSE_MAKEFILE ON)
ADD_SUBDIRECTORY(examples/c)
ADD_SUBDIRECTORY(tsim) ADD_SUBDIRECTORY(tsim)
ADD_SUBDIRECTORY(test/c) #ADD_SUBDIRECTORY(test/c)
ADD_SUBDIRECTORY(comparisonTest/tdengine) #ADD_SUBDIRECTORY(comparisonTest/tdengine)
...@@ -5,7 +5,7 @@ sql connect ...@@ -5,7 +5,7 @@ sql connect
print =============== show users print =============== show users
sql show users sql show users
if $rows != 3 then if $rows != 1 then
return -1 return -1
endi endi
...@@ -21,7 +21,7 @@ sql_error drop account root ...@@ -21,7 +21,7 @@ sql_error drop account root
print =============== create user1 print =============== create user1
sql create user user1 PASS 'user1' sql create user user1 PASS 'user1'
sql show users sql show users
if $rows != 4 then if $rows != 2 then
return -1 return -1
endi endi
...@@ -33,7 +33,7 @@ print $data30 $data31 $data32 ...@@ -33,7 +33,7 @@ print $data30 $data31 $data32
print =============== create user2 print =============== create user2
sql create user user2 PASS 'user2' sql create user user2 PASS 'user2'
sql show users sql show users
if $rows != 5 then if $rows != 3 then
return -1 return -1
endi endi
...@@ -46,7 +46,7 @@ print $data40 $data41 $data42 ...@@ -46,7 +46,7 @@ print $data40 $data41 $data42
print =============== drop user1 print =============== drop user1
sql drop user user1 sql drop user user1
sql show users sql show users
if $rows != 4 then if $rows != 2 then
return -1 return -1
endi endi
...@@ -62,7 +62,7 @@ system sh/exec.sh -n dnode1 -s start ...@@ -62,7 +62,7 @@ system sh/exec.sh -n dnode1 -s start
print =============== show users print =============== show users
sql show users sql show users
if $rows != 4 then if $rows != 2 then
return -1 return -1
endi endi
......
#!/bin/bash #!/bin/bash
set +e
#set -x
echo "Executing deploy.sh" echo "Executing deploy.sh"
if [ $# != 4 ]; then if [ $# != 4 ]; then
...@@ -50,12 +53,12 @@ else ...@@ -50,12 +53,12 @@ else
fi fi
if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2,3`
else else
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2`
fi fi
BUILD_DIR=$TAOS_DIR/$BIN_DIR/build BUILD_DIR=$TAOS_DIR/$BIN_DIR
SIM_DIR=$TAOS_DIR/sim SIM_DIR=$TAOS_DIR/sim
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
# exit 1 # exit 1
# fi # fi
set +e
#set -x
UNAME_BIN=`which uname` UNAME_BIN=`which uname`
OS_TYPE=`$UNAME_BIN` OS_TYPE=`$UNAME_BIN`
...@@ -62,16 +65,16 @@ else ...@@ -62,16 +65,16 @@ else
fi fi
if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2,3`
else else
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2`
fi fi
BUILD_DIR=$TAOS_DIR/$BIN_DIR/build BUILD_DIR=$TAOS_DIR/$BIN_DIR
SIM_DIR=$TAOS_DIR/sim SIM_DIR=$TAOS_DIR/sim
NODE_DIR=$SIM_DIR/$NODE_NAME NODE_DIR=$SIM_DIR/$NODE_NAME
EXE_DIR=$BUILD_DIR/bin EXE_DIR=$BUILD_DIR/source/dnode/mgmt/daemon
CFG_DIR=$NODE_DIR/cfg CFG_DIR=$NODE_DIR/cfg
LOG_DIR=$NODE_DIR/log LOG_DIR=$NODE_DIR/log
DATA_DIR=$NODE_DIR/data DATA_DIR=$NODE_DIR/data
......
...@@ -22,9 +22,6 @@ do ...@@ -22,9 +22,6 @@ do
f) f)
FILE_NAME=$OPTARG FILE_NAME=$OPTARG
;; ;;
a)
ASYNC=1
;;
v) v)
VALGRIND=1 VALGRIND=1
;; ;;
...@@ -60,32 +57,22 @@ else ...@@ -60,32 +57,22 @@ else
fi fi
if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then if [[ "$TAOSD_DIR" == *"$IN_TDINTERNAL"* ]]; then
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2,3` BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2,3`
else else
BIN_DIR=`find . -name "taosd"|grep bin|head -n1|cut -d '/' ${cut_opt}2` BIN_DIR=`find . -name "taosd"|grep source|head -n1|cut -d '/' ${cut_opt}2`
fi fi
BUILD_DIR=$TOP_DIR/$BIN_DIR/build BUILD_DIR=$TOP_DIR/$BIN_DIR
SIM_DIR=$TOP_DIR/sim SIM_DIR=$TOP_DIR/sim
if [ $ASYNC -eq 0 ]; then PROGRAM=$BUILD_DIR/tests/tsim/tsim
PROGRAM=$BUILD_DIR/bin/tsim
else
PROGRAM="$BUILD_DIR/bin/tsim -a"
fi
PRG_DIR=$SIM_DIR/tsim PRG_DIR=$SIM_DIR/tsim
CFG_DIR=$PRG_DIR/cfg CFG_DIR=$PRG_DIR/cfg
LOG_DIR=$PRG_DIR/log LOG_DIR=$PRG_DIR/log
DATA_DIR=$PRG_DIR/data DATA_DIR=$PRG_DIR/data
ARBITRATOR_PRG_DIR=$SIM_DIR/arbitrator
ARBITRATOR_LOG_DIR=$ARBITRATOR_PRG_DIR/log
chmod -R 777 $PRG_DIR chmod -R 777 $PRG_DIR
echo "------------------------------------------------------------------------" echo "------------------------------------------------------------------------"
echo "Start TDengine Testing Case ..." echo "Start TDengine Testing Case ..."
...@@ -96,12 +83,10 @@ echo "CFG_DIR : $CFG_DIR" ...@@ -96,12 +83,10 @@ echo "CFG_DIR : $CFG_DIR"
rm -rf $LOG_DIR rm -rf $LOG_DIR
rm -rf $CFG_DIR rm -rf $CFG_DIR
rm -rf $ARBITRATOR_LOG_DIR
mkdir -p $PRG_DIR mkdir -p $PRG_DIR
mkdir -p $LOG_DIR mkdir -p $LOG_DIR
mkdir -p $CFG_DIR mkdir -p $CFG_DIR
mkdir -p $ARBITRATOR_LOG_DIR
TAOS_CFG=$PRG_DIR/cfg/taos.cfg TAOS_CFG=$PRG_DIR/cfg/taos.cfg
touch -f $TAOS_CFG touch -f $TAOS_CFG
...@@ -115,7 +100,7 @@ echo "secondEp ${HOSTNAME}:7200" >> $TAOS_CFG ...@@ -115,7 +100,7 @@ echo "secondEp ${HOSTNAME}:7200" >> $TAOS_CFG
echo "serverPort 7100" >> $TAOS_CFG echo "serverPort 7100" >> $TAOS_CFG
echo "dataDir $DATA_DIR" >> $TAOS_CFG echo "dataDir $DATA_DIR" >> $TAOS_CFG
echo "logDir $LOG_DIR" >> $TAOS_CFG echo "logDir $LOG_DIR" >> $TAOS_CFG
echo "scriptDir ${CODE_DIR}/../script" >> $TAOS_CFG echo "scriptDir ${CODE_DIR}" >> $TAOS_CFG
echo "numOfLogLines 100000000" >> $TAOS_CFG echo "numOfLogLines 100000000" >> $TAOS_CFG
echo "rpcDebugFlag 143" >> $TAOS_CFG echo "rpcDebugFlag 143" >> $TAOS_CFG
echo "tmrDebugFlag 131" >> $TAOS_CFG echo "tmrDebugFlag 131" >> $TAOS_CFG
...@@ -141,7 +126,6 @@ if [ -n "$FILE_NAME" ]; then ...@@ -141,7 +126,6 @@ if [ -n "$FILE_NAME" ]; then
else else
echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f $FILE_NAME echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f $FILE_NAME
$PROGRAM -c $CFG_DIR -f $FILE_NAME $PROGRAM -c $CFG_DIR -f $FILE_NAME
# valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --show-leak-kinds=all -v --workaround-gcc296-bugs=yes --log-file=${CODE_DIR}/../script/valgrind.log $PROGRAM -c $CFG_DIR -f $FILE_NAME
fi fi
else else
echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f basicSuite.sim echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f basicSuite.sim
......
PROJECT(TDengine) aux_source_directory(src TSIM_SRC)
add_executable(tsim ${TSIM_SRC})
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) target_link_libraries(
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc) tsim
INCLUDE_DIRECTORIES(inc) PUBLIC taos
PUBLIC util
AUX_SOURCE_DIRECTORY(src SRC) PUBLIC common
ADD_EXECUTABLE(tsim ${SRC}) PUBLIC os
TARGET_LINK_LIBRARIES(tsim taos_static trpc tutil pthread cJson) PUBLIC cjson
)
target_include_directories(
tsim
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __SIM_H__ #ifndef _TD_SIM_H_
#define __SIM_H__ #define _TD_SIM_H_
#include <semaphore.h> #include <semaphore.h>
#include <stdbool.h> #include <stdbool.h>
...@@ -113,7 +113,7 @@ typedef struct { ...@@ -113,7 +113,7 @@ typedef struct {
int16_t errorJump; // sql jump flag, while '-x' exist in sql cmd, this flag int16_t errorJump; // sql jump flag, while '-x' exist in sql cmd, this flag
// will be SQL_JUMP_TRUE, otherwise is SQL_JUMP_FALSE */ // will be SQL_JUMP_TRUE, otherwise is SQL_JUMP_FALSE */
int16_t lineNum; // correspodning line number in original file int16_t lineNum; // correspodning line number in original file
int32_t optionOffset;// relative option offset int32_t optionOffset; // relative option offset
} SCmdLine; } SCmdLine;
typedef struct _var_t { typedef struct _var_t {
...@@ -125,7 +125,7 @@ typedef struct _var_t { ...@@ -125,7 +125,7 @@ typedef struct _var_t {
typedef struct _script_t { typedef struct _script_t {
int32_t type; int32_t type;
bool killed; bool killed;
void * taos; void *taos;
char rows[12]; // number of rows data retrieved char rows[12]; // number of rows data retrieved
char data[MAX_QUERY_ROW_NUM][MAX_QUERY_COL_NUM][MAX_QUERY_VALUE_LEN]; // query results char data[MAX_QUERY_ROW_NUM][MAX_QUERY_COL_NUM][MAX_QUERY_VALUE_LEN]; // query results
char system_exit_code[12]; char system_exit_code[12];
...@@ -136,7 +136,7 @@ typedef struct _script_t { ...@@ -136,7 +136,7 @@ typedef struct _script_t {
int32_t bgScriptLen; int32_t bgScriptLen;
char fileName[MAX_FILE_NAME_LEN]; // script file name char fileName[MAX_FILE_NAME_LEN]; // script file name
char error[MAX_ERROR_LEN]; char error[MAX_ERROR_LEN];
char * optionBuffer; char *optionBuffer;
SCmdLine *lines; // command list SCmdLine *lines; // command list
SVariable variables[MAX_VAR_LEN]; SVariable variables[MAX_VAR_LEN];
pthread_t bgPid; pthread_t bgPid;
...@@ -150,16 +150,15 @@ extern int32_t simScriptPos; ...@@ -150,16 +150,15 @@ extern int32_t simScriptPos;
extern int32_t simScriptSucced; extern int32_t simScriptSucced;
extern int32_t simDebugFlag; extern int32_t simDebugFlag;
extern char tsScriptDir[]; extern char tsScriptDir[];
extern bool simAsyncQuery;
extern bool abortExecution; extern bool abortExecution;
SScript *simParseScript(char *fileName); SScript *simParseScript(char *fileName);
SScript *simProcessCallOver(SScript *script); SScript *simProcessCallOver(SScript *script);
void * simExecuteScript(void *script); void *simExecuteScript(void *script);
void simInitsimCmdList(); void simInitsimCmdList();
bool simSystemInit(); bool simSystemInit();
void simSystemCleanUp(); void simSystemCleanUp();
char * simGetVariable(SScript *script, char *varName, int32_t varLen); char *simGetVariable(SScript *script, char *varName, int32_t varLen);
bool simExecuteExpCmd(SScript *script, char *option); bool simExecuteExpCmd(SScript *script, char *option);
bool simExecuteTestCmd(SScript *script, char *option); bool simExecuteTestCmd(SScript *script, char *option);
bool simExecuteGotoCmd(SScript *script, char *option); bool simExecuteGotoCmd(SScript *script, char *option);
...@@ -178,4 +177,4 @@ bool simExecuteLineInsertCmd(SScript *script, char *option); ...@@ -178,4 +177,4 @@ bool simExecuteLineInsertCmd(SScript *script, char *option);
bool simExecuteLineInsertErrorCmd(SScript *script, char *option); bool simExecuteLineInsertErrorCmd(SScript *script, char *option);
void simVisuallizeOption(SScript *script, char *src, char *dst); void simVisuallizeOption(SScript *script, char *src, char *dst);
#endif #endif /*_TD_SIM_H_*/
\ No newline at end of file \ No newline at end of file
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __SIM_PARSE_H__ #ifndef _TD_SIM_PARSE_H_
#define __SIM_PARSE_H__ #define _TD_SIM_PARSE_H_
#define MAX_NUM_CMD 64 #define MAX_NUM_CMD 64
#define MAX_NUM_LABLES 100 #define MAX_NUM_LABLES 100
...@@ -52,4 +52,4 @@ typedef struct { ...@@ -52,4 +52,4 @@ typedef struct {
bool simParseExpression(char *token, int32_t lineNum); bool simParseExpression(char *token, int32_t lineNum);
#endif #endif /*_TD_SIM_PARSE_H_*/
\ No newline at end of file \ No newline at end of file
...@@ -14,14 +14,14 @@ ...@@ -14,14 +14,14 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "../../../include/client/taos.h"
#include "cJSON.h" #include "cJSON.h"
#include "os.h" #include "os.h"
#include "sim.h" #include "sim.h"
#include "taos.h"
#include "taoserror.h" #include "taoserror.h"
#include "tglobal.h" #include "tglobal.h"
#include "ttypes.h"
#include "tutil.h" #include "tutil.h"
#undef TAOS_MEM_CHECK
void simLogSql(char *sql, bool useSharp) { void simLogSql(char *sql, bool useSharp) {
static FILE *fp = NULL; static FILE *fp = NULL;
...@@ -74,7 +74,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { ...@@ -74,7 +74,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
return "null"; return "null";
} }
char * keyName; char *keyName;
int32_t keyLen; int32_t keyLen;
paGetToken(varName + 6, &keyName, &keyLen); paGetToken(varName + 6, &keyName, &keyLen);
...@@ -91,7 +91,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { ...@@ -91,7 +91,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
return "null"; return "null";
} }
char * keyName; char *keyName;
int32_t keyLen; int32_t keyLen;
paGetToken(varName + 7, &keyName, &keyLen); paGetToken(varName + 7, &keyName, &keyLen);
...@@ -144,7 +144,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) { ...@@ -144,7 +144,7 @@ char *simGetVariable(SScript *script, char *varName, int32_t varLen) {
} }
int32_t simExecuteExpression(SScript *script, char *exp) { int32_t simExecuteExpression(SScript *script, char *exp) {
char * op1, *op2, *var1, *var2, *var3, *rest; char *op1, *op2, *var1, *var2, *var3, *rest;
int32_t op1Len, op2Len, var1Len, var2Len, var3Len, val0, val1; int32_t op1Len, op2Len, var1Len, var2Len, var3Len, val0, val1;
char t0[1024], t1[1024], t2[1024], t3[2048]; char t0[1024], t1[1024], t2[1024], t3[2048];
int32_t result; int32_t result;
...@@ -302,7 +302,7 @@ bool simExecuteRunBackCmd(SScript *script, char *option) { ...@@ -302,7 +302,7 @@ bool simExecuteRunBackCmd(SScript *script, char *option) {
} }
void simReplaceShToBat(char *dst) { void simReplaceShToBat(char *dst) {
char* sh = strstr(dst, ".sh"); char *sh = strstr(dst, ".sh");
if (sh != NULL) { if (sh != NULL) {
int32_t dstLen = (int32_t)strlen(dst); int32_t dstLen = (int32_t)strlen(dst);
char *end = dst + dstLen; char *end = dst + dstLen;
...@@ -436,7 +436,7 @@ bool simExecuteReturnCmd(SScript *script, char *option) { ...@@ -436,7 +436,7 @@ bool simExecuteReturnCmd(SScript *script, char *option) {
} }
void simVisuallizeOption(SScript *script, char *src, char *dst) { void simVisuallizeOption(SScript *script, char *src, char *dst) {
char * var, *token, *value; char *var, *token, *value;
int32_t dstLen, srcLen, tokenLen; int32_t dstLen, srcLen, tokenLen;
dst[0] = 0, dstLen = 0; dst[0] = 0, dstLen = 0;
...@@ -466,10 +466,6 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) { ...@@ -466,10 +466,6 @@ void simVisuallizeOption(SScript *script, char *src, char *dst) {
strcpy(dst + dstLen, src); strcpy(dst + dstLen, src);
} }
void simCloseRestFulConnect(SScript *script) {
memset(script->auth, 0, sizeof(script->auth));
}
void simCloseNativeConnect(SScript *script) { void simCloseNativeConnect(SScript *script) {
if (script->taos == NULL) return; if (script->taos == NULL) return;
...@@ -479,168 +475,7 @@ void simCloseNativeConnect(SScript *script) { ...@@ -479,168 +475,7 @@ void simCloseNativeConnect(SScript *script) {
script->taos = NULL; script->taos = NULL;
} }
void simCloseTaosdConnect(SScript *script) { void simCloseTaosdConnect(SScript *script) { simCloseNativeConnect(script); }
if (simAsyncQuery) {
simCloseRestFulConnect(script);
} else {
simCloseNativeConnect(script);
}
}
// {"status":"succ","code":0,"desc":"/KfeAzX/f9na8qdtNZmtONryp201ma04bEl8LcvLUd7a8qdtNZmtONryp201ma04"}
// {"status":"succ","head":["affected_rows"],"data":[[1]],"rows":1}
// {"status":"succ","head":["ts","i"],"data":[["2017-12-25 21:28:41.022",1],["2017-12-25 21:28:42.022",2],["2017-12-25 21:28:43.022",3],["2017-12-25 21:28:44.022",4],["2017-12-25 21:28:45.022",5],["2017-12-25 21:28:46.022",6],["2017-12-25 21:28:47.022",7],["2017-12-25 21:28:48.022",8],["2017-12-25 21:28:49.022",9],["2017-12-25 21:28:50.022",10]],"rows":10}
int32_t simParseHttpCommandResult(SScript *script, char *command) {
cJSON* root = cJSON_Parse(command);
if (root == NULL) {
simError("script:%s, failed to parse json, response:%s", script->fileName, command);
return -1;
}
cJSON *status = cJSON_GetObjectItem(root, "status");
if (status == NULL) {
simError("script:%s, failed to parse json, status is null, response:%s", script->fileName, command);
cJSON_Delete(root);
return -1;
}
if (status->valuestring == NULL || strlen(status->valuestring) == 0) {
simError("script:%s, failed to parse json, status value is null, response:%s", script->fileName, command);
cJSON_Delete(root);
return -1;
}
if (strcmp(status->valuestring, "succ") != 0) {
cJSON *code = cJSON_GetObjectItem(root, "code");
if (code == NULL) {
simError("script:%s, failed to parse json, code is null, response:%s", script->fileName, command);
cJSON_Delete(root);
return -1;
}
int32_t retcode = (int32_t)code->valueint;
if (retcode != 1017) {
simError("script:%s, json:status:%s not equal to succ, response:%s", script->fileName, status->valuestring,
command);
cJSON_Delete(root);
return retcode;
} else {
simDebug("script:%s, json:status:%s not equal to succ, but code is %d, response:%s", script->fileName,
status->valuestring, retcode, command);
cJSON_Delete(root);
return 0;
}
}
cJSON *desc = cJSON_GetObjectItem(root, "desc");
if (desc != NULL) {
if (desc->valuestring == NULL || strlen(desc->valuestring) == 0) {
simError("script:%s, failed to parse json, desc value is null, response:%s", script->fileName, command);
cJSON_Delete(root);
return -1;
}
strcpy(script->auth, desc->valuestring);
cJSON_Delete(root);
return 0;
}
cJSON *data = cJSON_GetObjectItem(root, "data");
if (data == NULL) {
simError("script:%s, failed to parse json, data is null, response:%s", script->fileName, command);
cJSON_Delete(root);
return -1;
}
int32_t rowsize = cJSON_GetArraySize(data);
if (rowsize < 0) {
simError("script:%s, failed to parse json:data, data size %d, response:%s", script->fileName, rowsize, command);
cJSON_Delete(root);
return -1;
}
int32_t rowIndex = 0;
sprintf(script->rows, "%d", rowsize);
for (int32_t r = 0; r < rowsize; ++r) {
cJSON *row = cJSON_GetArrayItem(data, r);
if (row == NULL) continue;
if (rowIndex++ >= 10) break;
int32_t colsize = cJSON_GetArraySize(row);
if (colsize < 0) {
break;
}
colsize = MIN(10, colsize);
for (int32_t c = 0; c < colsize; ++c) {
cJSON *col = cJSON_GetArrayItem(row, c);
if (col->valuestring != NULL) {
strcpy(script->data[r][c], col->valuestring);
} else {
if (col->numberstring[0] == 0) {
strcpy(script->data[r][c], "null");
} else {
strcpy(script->data[r][c], col->numberstring);
}
}
}
}
return 0;
}
int32_t simExecuteRestFulCommand(SScript *script, char *command) {
char buf[5000] = {0};
sprintf(buf, "%s 2>/dev/null", command);
FILE *fp = popen(buf, "r");
if (fp == NULL) {
simError("failed to execute %s", buf);
return -1;
}
int32_t mallocSize = 2000;
int32_t alreadyReadSize = 0;
char * content = malloc(mallocSize);
while (!feof(fp)) {
int32_t availSize = mallocSize - alreadyReadSize;
int32_t len = (int32_t)fread(content + alreadyReadSize, 1, availSize, fp);
if (len >= availSize) {
alreadyReadSize += len;
mallocSize *= 2;
content = realloc(content, mallocSize);
}
}
pclose(fp);
return simParseHttpCommandResult(script, content);
}
bool simCreateRestFulConnect(SScript *script, char *user, char *pass) {
char command[4096];
sprintf(command, "curl 127.0.0.1:6041/rest/login/%s/%s", user, pass);
bool success = false;
for (int32_t attempt = 0; attempt < 10; ++attempt) {
success = simExecuteRestFulCommand(script, command) == 0;
if (!success) {
simDebug("script:%s, user:%s connect taosd failed:%s, attempt:%d", script->fileName, user, taos_errstr(NULL),
attempt);
taosMsleep(1000);
} else {
simDebug("script:%s, user:%s connect taosd successed, attempt:%d", script->fileName, user, attempt);
break;
}
}
if (!success) {
sprintf(script->error, "lineNum:%d. connect taosd failed:%s", script->lines[script->linePos].lineNum,
taos_errstr(NULL));
return false;
}
simDebug("script:%s, connect taosd successed, auth:%p", script->fileName, script->auth);
return true;
}
bool simCreateNativeConnect(SScript *script, char *user, char *pass) { bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
simCloseTaosdConnect(script); simCloseTaosdConnect(script);
...@@ -651,7 +486,7 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) { ...@@ -651,7 +486,7 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
return false; return false;
} }
taos = taos_connect(NULL, user, pass, NULL, tsDnodeShellPort); taos = taos_connect(NULL, user, pass, NULL, 0);
if (taos == NULL) { if (taos == NULL) {
simDebug("script:%s, user:%s connect taosd failed:%s, attempt:%d", script->fileName, user, taos_errstr(NULL), simDebug("script:%s, user:%s connect taosd failed:%s, attempt:%d", script->fileName, user, taos_errstr(NULL),
attempt); attempt);
...@@ -675,8 +510,8 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) { ...@@ -675,8 +510,8 @@ bool simCreateNativeConnect(SScript *script, char *user, char *pass) {
} }
bool simCreateTaosdConnect(SScript *script, char *rest) { bool simCreateTaosdConnect(SScript *script, char *rest) {
char * user = TSDB_DEFAULT_USER; char *user = TSDB_DEFAULT_USER;
char * token; char *token;
int32_t tokenLen; int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
...@@ -684,18 +519,14 @@ bool simCreateTaosdConnect(SScript *script, char *rest) { ...@@ -684,18 +519,14 @@ bool simCreateTaosdConnect(SScript *script, char *rest) {
user = token; user = token;
} }
if (simAsyncQuery) {
return simCreateRestFulConnect(script, user, TSDB_DEFAULT_PASS);
} else {
return simCreateNativeConnect(script, user, TSDB_DEFAULT_PASS); return simCreateNativeConnect(script, user, TSDB_DEFAULT_PASS);
}
} }
bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
char timeStr[30] = {0}; char timeStr[30] = {0};
time_t tt; time_t tt;
struct tm *tp; struct tm *tp;
SCmdLine * line = &script->lines[script->linePos]; SCmdLine *line = &script->lines[script->linePos];
int32_t ret = -1; int32_t ret = -1;
TAOS_RES *pSql = NULL; TAOS_RES *pSql = NULL;
...@@ -710,7 +541,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { ...@@ -710,7 +541,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
pSql = taos_query(script->taos, rest); pSql = taos_query(script->taos, rest);
ret = taos_errno(pSql); ret = taos_errno(pSql);
if (ret == TSDB_CODE_MND_TABLE_ALREADY_EXIST || ret == TSDB_CODE_MND_DB_ALREADY_EXIST) { if (ret == TSDB_CODE_MND_STB_ALREADY_EXIST || ret == TSDB_CODE_MND_DB_ALREADY_EXIST) {
simDebug("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret & 0XFFFF, simDebug("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret & 0XFFFF,
tstrerror(ret)); tstrerror(ret));
ret = 0; ret = 0;
...@@ -756,7 +587,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { ...@@ -756,7 +587,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
while ((row = taos_fetch_row(pSql))) { while ((row = taos_fetch_row(pSql))) {
if (numOfRows < MAX_QUERY_ROW_NUM) { if (numOfRows < MAX_QUERY_ROW_NUM) {
TAOS_FIELD *fields = taos_fetch_fields(pSql); TAOS_FIELD *fields = taos_fetch_fields(pSql);
int32_t * length = taos_fetch_lengths(pSql); int32_t *length = taos_fetch_lengths(pSql);
for (int32_t i = 0; i < num_fields; i++) { for (int32_t i = 0; i < num_fields; i++) {
char *value = NULL; char *value = NULL;
...@@ -780,7 +611,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { ...@@ -780,7 +611,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
sprintf(value, "%d", *((int8_t *)row[i])); sprintf(value, "%d", *((int8_t *)row[i]));
break; break;
case TSDB_DATA_TYPE_UTINYINT: case TSDB_DATA_TYPE_UTINYINT:
sprintf(value, "%u", *((uint8_t*)row[i])); sprintf(value, "%u", *((uint8_t *)row[i]));
break; break;
case TSDB_DATA_TYPE_SMALLINT: case TSDB_DATA_TYPE_SMALLINT:
sprintf(value, "%d", *((int16_t *)row[i])); sprintf(value, "%d", *((int16_t *)row[i]));
...@@ -877,41 +708,6 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { ...@@ -877,41 +708,6 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
return true; return true;
} }
bool simExecuteRestFulSqlCommand(SScript *script, char *rest) {
SCmdLine *line = &script->lines[script->linePos];
char command[4096];
sprintf(command, "curl -H 'Authorization: Taosd %s' -d \"%s\" 127.0.0.1:6041/rest/sql", script->auth, rest);
int32_t ret = -1;
for (int32_t attempt = 0; attempt < 10; ++attempt) {
ret = simExecuteRestFulCommand(script, command);
if (ret == TSDB_CODE_MND_TABLE_ALREADY_EXIST || ret == TSDB_CODE_MND_DB_ALREADY_EXIST) {
simDebug("script:%s, taos:%p, %s success, ret:%d:%s", script->fileName, script->taos, rest, ret & 0XFFFF,
tstrerror(ret));
ret = 0;
break;
} else if (ret != 0) {
simDebug("script:%s, taos:%p, %s failed, ret:%d", script->fileName, script->taos, rest, ret);
if (line->errorJump == SQL_JUMP_TRUE) {
script->linePos = line->jump;
return true;
}
taosMsleep(1000);
} else {
break;
}
}
if (ret) {
sprintf(script->error, "lineNum:%d. sql:%s failed, ret:%d", line->lineNum, rest, ret);
return false;
}
script->linePos++;
return true;
}
bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) { bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) {
char buf[3000]; char buf[3000];
SCmdLine *line = &script->lines[script->linePos]; SCmdLine *line = &script->lines[script->linePos];
...@@ -935,7 +731,7 @@ bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) { ...@@ -935,7 +731,7 @@ bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) {
return true; return true;
} }
if ((!simAsyncQuery && script->taos == NULL) || (simAsyncQuery && script->auth[0] == 0)) { if (script->taos == NULL) {
if (!simCreateTaosdConnect(script, "connect root")) { if (!simCreateTaosdConnect(script, "connect root")) {
if (line->errorJump == SQL_JUMP_TRUE) { if (line->errorJump == SQL_JUMP_TRUE) {
script->linePos = line->jump; script->linePos = line->jump;
...@@ -951,11 +747,7 @@ bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) { ...@@ -951,11 +747,7 @@ bool simExecuteSqlImpCmd(SScript *script, char *rest, bool isSlow) {
return true; return true;
} }
if (simAsyncQuery) {
return simExecuteRestFulSqlCommand(script, rest);
} else {
return simExecuteNativeSqlCommand(script, rest, isSlow); return simExecuteNativeSqlCommand(script, rest, isSlow);
}
} }
bool simExecuteSqlCmd(SScript *script, char *rest) { bool simExecuteSqlCmd(SScript *script, char *rest) {
...@@ -1032,7 +824,7 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) { ...@@ -1032,7 +824,7 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
return true; return true;
} }
if ((!simAsyncQuery && script->taos == NULL) || (simAsyncQuery && script->auth[0] == 0)) { if (script->taos == NULL) {
if (!simCreateTaosdConnect(script, "connect root")) { if (!simCreateTaosdConnect(script, "connect root")) {
if (line->errorJump == SQL_JUMP_TRUE) { if (line->errorJump == SQL_JUMP_TRUE) {
script->linePos = line->jump; script->linePos = line->jump;
...@@ -1048,17 +840,9 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) { ...@@ -1048,17 +840,9 @@ bool simExecuteSqlErrorCmd(SScript *script, char *rest) {
return true; return true;
} }
int32_t ret; TAOS_RES *pSql = pSql = taos_query(script->taos, rest);
TAOS_RES *pSql = NULL; int32_t ret = taos_errno(pSql);
if (simAsyncQuery) {
char command[4096];
sprintf(command, "curl -H 'Authorization: Taosd %s' -d '%s' 127.0.0.1:6041/rest/sql", script->auth, rest);
ret = simExecuteRestFulCommand(script, command);
} else {
pSql = taos_query(script->taos, rest);
ret = taos_errno(pSql);
taos_free_result(pSql); taos_free_result(pSql);
}
if (ret != TSDB_CODE_SUCCESS) { if (ret != TSDB_CODE_SUCCESS) {
simDebug("script:%s, taos:%p, %s execute, expect failed, so success, ret:%d:%s", script->fileName, script->taos, simDebug("script:%s, taos:%p, %s execute, expect failed, so success, ret:%d:%s", script->fileName, script->taos,
...@@ -1083,15 +867,19 @@ bool simExecuteLineInsertCmd(SScript *script, char *rest) { ...@@ -1083,15 +867,19 @@ bool simExecuteLineInsertCmd(SScript *script, char *rest) {
simInfo("script:%s, %s", script->fileName, rest); simInfo("script:%s, %s", script->fileName, rest);
simLogSql(buf, true); simLogSql(buf, true);
char * lines[] = {rest}; char *lines[] = {rest};
#if 0
int32_t ret = taos_insert_lines(script->taos, lines, 1); int32_t ret = taos_insert_lines(script->taos, lines, 1);
#else
int32_t ret = 0;
#endif
if (ret == TSDB_CODE_SUCCESS) { if (ret == TSDB_CODE_SUCCESS) {
simDebug("script:%s, taos:%p, %s executed. success.", script->fileName, script->taos, rest); simDebug("script:%s, taos:%p, %s executed. success.", script->fileName, script->taos, rest);
script->linePos++; script->linePos++;
return true; return true;
} else { } else {
sprintf(script->error, "lineNum: %d. line: %s failed, ret:%d:%s", line->lineNum, rest, sprintf(script->error, "lineNum: %d. line: %s failed, ret:%d:%s", line->lineNum, rest, ret & 0XFFFF,
ret & 0XFFFF, tstrerror(ret)); tstrerror(ret));
return false; return false;
} }
} }
...@@ -1106,15 +894,20 @@ bool simExecuteLineInsertErrorCmd(SScript *script, char *rest) { ...@@ -1106,15 +894,20 @@ bool simExecuteLineInsertErrorCmd(SScript *script, char *rest) {
simInfo("script:%s, %s", script->fileName, rest); simInfo("script:%s, %s", script->fileName, rest);
simLogSql(buf, true); simLogSql(buf, true);
char * lines[] = {rest}; char *lines[] = {rest};
#if 0
int32_t ret = taos_insert_lines(script->taos, lines, 1); int32_t ret = taos_insert_lines(script->taos, lines, 1);
#else
int32_t ret = 0;
#endif
if (ret == TSDB_CODE_SUCCESS) { if (ret == TSDB_CODE_SUCCESS) {
sprintf(script->error, "script:%s, taos:%p, %s executed. expect failed, but success.", script->fileName, script->taos, rest); sprintf(script->error, "script:%s, taos:%p, %s executed. expect failed, but success.", script->fileName,
script->taos, rest);
script->linePos++; script->linePos++;
return false; return false;
} else { } else {
simDebug("lineNum: %d. line: %s failed, ret:%d:%s. Expect failed, so success", line->lineNum, rest, simDebug("lineNum: %d. line: %s failed, ret:%d:%s. Expect failed, so success", line->lineNum, rest, ret & 0XFFFF,
ret & 0XFFFF, tstrerror(ret)); tstrerror(ret));
return true; return true;
} }
} }
...@@ -15,19 +15,17 @@ ...@@ -15,19 +15,17 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "tglobal.h"
#include "sim.h" #include "sim.h"
#undef TAOS_MEM_CHECK #include "tglobal.h"
bool simAsyncQuery = false;
bool simExecSuccess = false; bool simExecSuccess = false;
bool abortExecution = false; bool abortExecution = false;
void simHandleSignal(int32_t signo, void *sigInfo, void *context) { void simHandleSignal(int32_t signo, void *sigInfo, void *context) {
simSystemCleanUp(); simSystemCleanUp();
abortExecution = true; abortExecution = true;
// runningScript->killed = true; // runningScript->killed = true;
// exit(1); // exit(1);
} }
int32_t main(int32_t argc, char *argv[]) { int32_t main(int32_t argc, char *argv[]) {
...@@ -38,8 +36,6 @@ int32_t main(int32_t argc, char *argv[]) { ...@@ -38,8 +36,6 @@ int32_t main(int32_t argc, char *argv[]) {
tstrncpy(configDir, argv[++i], 128); tstrncpy(configDir, argv[++i], 128);
} else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) { } else if (strcmp(argv[i], "-f") == 0 && i < argc - 1) {
strcpy(scriptFile, argv[++i]); strcpy(scriptFile, argv[++i]);
} else if (strcmp(argv[i], "-a") == 0) {
simAsyncQuery = true;
} else { } else {
printf("usage: %s [options] \n", argv[0]); printf("usage: %s [options] \n", argv[0]);
printf(" [-c config]: config directory, default is: %s\n", configDir); printf(" [-c config]: config directory, default is: %s\n", configDir);
......
...@@ -60,9 +60,9 @@ ...@@ -60,9 +60,9 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "sim.h" #include "sim.h"
#include "simParse.h"
#include "tutil.h" #include "tutil.h"
#undef TAOS_MEM_CHECK
#include "simParse.h"
static SCommand *cmdHashList[MAX_NUM_CMD]; static SCommand *cmdHashList[MAX_NUM_CMD];
static SCmdLine cmdLine[MAX_CMD_LINES]; static SCmdLine cmdLine[MAX_CMD_LINES];
...@@ -177,11 +177,11 @@ SScript *simBuildScriptObj(char *fileName) { ...@@ -177,11 +177,11 @@ SScript *simBuildScriptObj(char *fileName) {
} }
SScript *simParseScript(char *fileName) { SScript *simParseScript(char *fileName) {
FILE * fd; FILE *fd;
int32_t tokenLen, lineNum = 0; int32_t tokenLen, lineNum = 0;
char buffer[MAX_LINE_LEN], name[128], *token, *rest; char buffer[MAX_LINE_LEN], name[128], *token, *rest;
SCommand *pCmd; SCommand *pCmd;
SScript * script; SScript *script;
if ((fileName[0] == '.') || (fileName[0] == '/')) { if ((fileName[0] == '.') || (fileName[0] == '/')) {
strcpy(name, fileName); strcpy(name, fileName);
...@@ -252,7 +252,7 @@ SScript *simParseScript(char *fileName) { ...@@ -252,7 +252,7 @@ SScript *simParseScript(char *fileName) {
} }
int32_t simCheckExpression(char *exp) { int32_t simCheckExpression(char *exp) {
char * op1, *op2, *op, *rest; char *op1, *op2, *op, *rest;
int32_t op1Len, op2Len, opLen; int32_t op1Len, op2Len, opLen;
rest = paGetToken(exp, &op1, &op1Len); rest = paGetToken(exp, &op1, &op1Len);
...@@ -336,7 +336,7 @@ bool simParseExpression(char *token, int32_t lineNum) { ...@@ -336,7 +336,7 @@ bool simParseExpression(char *token, int32_t lineNum) {
} }
bool simParseIfCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseIfCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * ret; char *ret;
int32_t expLen; int32_t expLen;
expLen = simCheckExpression(rest); expLen = simCheckExpression(rest);
...@@ -502,7 +502,7 @@ bool simParseEndwCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -502,7 +502,7 @@ bool simParseEndwCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
} }
bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token; char *token;
int32_t tokenLen; int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
...@@ -525,7 +525,7 @@ bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -525,7 +525,7 @@ bool simParseSwitchCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
} }
bool simParseCaseCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseCaseCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token; char *token;
int32_t tokenLen; int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
...@@ -666,7 +666,7 @@ bool simParsePrintCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -666,7 +666,7 @@ bool simParsePrintCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
void simCheckSqlOption(char *rest) { void simCheckSqlOption(char *rest) {
int32_t valueLen; int32_t valueLen;
char * value, *xpos; char *value, *xpos;
xpos = strstr(rest, " -x"); // need a blank xpos = strstr(rest, " -x"); // need a blank
if (xpos) { if (xpos) {
...@@ -750,7 +750,7 @@ bool simParseSystemContentCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -750,7 +750,7 @@ bool simParseSystemContentCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
} }
bool simParseSleepCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseSleepCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token; char *token;
int32_t tokenLen; int32_t tokenLen;
cmdLine[numOfLines].cmdno = SIM_CMD_SLEEP; cmdLine[numOfLines].cmdno = SIM_CMD_SLEEP;
...@@ -769,7 +769,7 @@ bool simParseSleepCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -769,7 +769,7 @@ bool simParseSleepCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
} }
bool simParseReturnCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseReturnCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token; char *token;
int32_t tokenLen; int32_t tokenLen;
cmdLine[numOfLines].cmdno = SIM_CMD_RETURN; cmdLine[numOfLines].cmdno = SIM_CMD_RETURN;
...@@ -788,7 +788,7 @@ bool simParseReturnCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -788,7 +788,7 @@ bool simParseReturnCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
} }
bool simParseGotoCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseGotoCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token; char *token;
int32_t tokenLen; int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
...@@ -811,7 +811,7 @@ bool simParseGotoCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -811,7 +811,7 @@ bool simParseGotoCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
} }
bool simParseRunCmd(char *rest, SCommand *pCmd, int32_t lineNum) { bool simParseRunCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
char * token; char *token;
int32_t tokenLen; int32_t tokenLen;
rest = paGetToken(rest, &token, &tokenLen); rest = paGetToken(rest, &token, &tokenLen);
...@@ -838,7 +838,7 @@ bool simParseRunBackCmd(char *rest, SCommand *pCmd, int32_t lineNum) { ...@@ -838,7 +838,7 @@ bool simParseRunBackCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
return true; return true;
} }
bool simParseLineInsertCmd(char* rest, SCommand* pCmd, int32_t lineNum) { bool simParseLineInsertCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int32_t expLen; int32_t expLen;
rest++; rest++;
...@@ -854,7 +854,7 @@ bool simParseLineInsertCmd(char* rest, SCommand* pCmd, int32_t lineNum) { ...@@ -854,7 +854,7 @@ bool simParseLineInsertCmd(char* rest, SCommand* pCmd, int32_t lineNum) {
return true; return true;
} }
bool simParseLineInsertErrorCmd(char* rest, SCommand* pCmd, int32_t lineNum) { bool simParseLineInsertErrorCmd(char *rest, SCommand *pCmd, int32_t lineNum) {
int32_t expLen; int32_t expLen;
rest++; rest++;
......
...@@ -14,15 +14,15 @@ ...@@ -14,15 +14,15 @@
*/ */
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "../../../include/client/taos.h"
#include "os.h" #include "os.h"
#include "sim.h" #include "sim.h"
#include "taos.h"
#include "taoserror.h" #include "taoserror.h"
#include "tglobal.h" #include "tglobal.h"
#include "tsocket.h"
#include "ttimer.h" #include "ttimer.h"
#include "tutil.h" #include "tutil.h"
#undef TAOS_MEM_CHECK #include "tglobal.h"
#include "tconfig.h"
SScript *simScriptList[MAX_MAIN_SCRIPT_NUM]; SScript *simScriptList[MAX_MAIN_SCRIPT_NUM];
SCommand simCmdList[SIM_CMD_END]; SCommand simCmdList[SIM_CMD_END];
...@@ -81,10 +81,11 @@ char *simParseHostName(char *varName) { ...@@ -81,10 +81,11 @@ char *simParseHostName(char *varName) {
} }
bool simSystemInit() { bool simSystemInit() {
if (taos_init()) {
return false;
}
taosGetFqdn(simHostName); taosGetFqdn(simHostName);
taosInitGlobalCfg();
taosReadCfgFromFile();
simInitsimCmdList(); simInitsimCmdList();
memset(simScriptList, 0, sizeof(SScript *) * MAX_MAIN_SCRIPT_NUM); memset(simScriptList, 0, sizeof(SScript *) * MAX_MAIN_SCRIPT_NUM);
return true; return true;
...@@ -171,7 +172,7 @@ void *simExecuteScript(void *inputScript) { ...@@ -171,7 +172,7 @@ void *simExecuteScript(void *inputScript) {
} }
} else { } else {
SCmdLine *line = &script->lines[script->linePos]; SCmdLine *line = &script->lines[script->linePos];
char * option = script->optionBuffer + line->optionOffset; char *option = script->optionBuffer + line->optionOffset;
simDebug("script:%s, line:%d with option \"%s\"", script->fileName, line->lineNum, option); simDebug("script:%s, line:%d with option \"%s\"", script->fileName, line->lineNum, option);
SCommand *cmd = &simCmdList[line->cmdno]; SCommand *cmd = &simCmdList[line->cmdno];
......
add_subdirectory(shell)
\ No newline at end of file
aux_source_directory(src SHELL_SRC)
list(REMOVE_ITEM SHELL_SRC src/shellWindows.c)
list(REMOVE_ITEM SHELL_SRC src/shellDarwin.c)
add_executable(shell ${SHELL_SRC})
target_link_libraries(
shell
PUBLIC taos
PUBLIC util
PUBLIC common
PUBLIC os
)
target_include_directories(
shell
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
)
SET_TARGET_PROPERTIES(shell PROPERTIES OUTPUT_NAME taos)
...@@ -13,13 +13,13 @@ ...@@ -13,13 +13,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __SHELL__ #ifndef _TD_SHELL_H_
#define __SHELL__ #define _TD_SHELL_H_
#include "../../../../include/client/taos.h" #include "os.h"
#include "stdbool.h"
#include "taos.h"
#include "taosdef.h" #include "taosdef.h"
#include "tsclient.h"
#define MAX_USERNAME_SIZE 64 #define MAX_USERNAME_SIZE 64
#define MAX_DBNAME_SIZE 64 #define MAX_DBNAME_SIZE 64
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __COMMAND_STRUCT__ #ifndef _TD_SHELL_COMMAND_H_
#define __COMMAND_STRUCT__ #define _TD_SHELL_COMMAND_H_
#include "shell.h" #include "shell.h"
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include "shell.h" #include "shell.h"
#include "shellCommand.h" #include "shellCommand.h"
#include <regex.h>
extern int wcwidth(wchar_t c); extern int wcwidth(wchar_t c);
extern int wcswidth(const wchar_t *s, size_t n); extern int wcswidth(const wchar_t *s, size_t n);
typedef struct { typedef struct {
......
...@@ -21,13 +21,14 @@ ...@@ -21,13 +21,14 @@
#include "os.h" #include "os.h"
#include "shell.h" #include "shell.h"
#include "shellCommand.h" #include "shellCommand.h"
#include "tutil.h"
#include "taosdef.h" #include "taosdef.h"
#include "taoserror.h" #include "taoserror.h"
#include "tglobal.h" #include "tglobal.h"
#include "tsclient.h" #include "ttypes.h"
#include "tutil.h"
#include <regex.h> #include <regex.h>
#include <wordexp.h>
/**************** Global variables ****************/ /**************** Global variables ****************/
#ifdef _TD_POWER_ #ifdef _TD_POWER_
...@@ -89,12 +90,6 @@ TAOS *shellInit(SShellArguments *_args) { ...@@ -89,12 +90,6 @@ TAOS *shellInit(SShellArguments *_args) {
_args->user = TSDB_DEFAULT_USER; _args->user = TSDB_DEFAULT_USER;
} }
if (taos_init()) {
printf("failed to init taos\n");
fflush(stdout);
return NULL;
}
// Connect to the database. // Connect to the database.
TAOS *con = NULL; TAOS *con = NULL;
if (_args->auth == NULL) { if (_args->auth == NULL) {
...@@ -127,6 +122,7 @@ TAOS *shellInit(SShellArguments *_args) { ...@@ -127,6 +122,7 @@ TAOS *shellInit(SShellArguments *_args) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
#if 0
#ifndef WINDOWS #ifndef WINDOWS
if (_args->dir[0] != 0) { if (_args->dir[0] != 0) {
source_dir(con, _args); source_dir(con, _args);
...@@ -139,12 +135,13 @@ TAOS *shellInit(SShellArguments *_args) { ...@@ -139,12 +135,13 @@ TAOS *shellInit(SShellArguments *_args) {
taos_close(con); taos_close(con);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
#endif
#endif #endif
return con; return con;
} }
static bool isEmptyCommand(const char* cmd) { static bool isEmptyCommand(const char *cmd) {
for (char c = *cmd++; c != 0; c = *cmd++) { for (char c = *cmd++; c != 0; c = *cmd++) {
if (c != ' ' && c != '\t' && c != ';') { if (c != ' ' && c != '\t' && c != ';') {
return false; return false;
...@@ -153,7 +150,6 @@ static bool isEmptyCommand(const char* cmd) { ...@@ -153,7 +150,6 @@ static bool isEmptyCommand(const char* cmd) {
return true; return true;
} }
static int32_t shellRunSingleCommand(TAOS *con, char *command) { static int32_t shellRunSingleCommand(TAOS *con, char *command) {
/* If command is empty just return */ /* If command is empty just return */
if (isEmptyCommand(command)) { if (isEmptyCommand(command)) {
...@@ -176,10 +172,11 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) { ...@@ -176,10 +172,11 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) {
return 0; return 0;
} }
if (regex_match(command, "^[\t ]*set[ \t]+max_binary_display_width[ \t]+(default|[1-9][0-9]*)[ \t;]*$", REG_EXTENDED | REG_ICASE)) { if (regex_match(command, "^[\t ]*set[ \t]+max_binary_display_width[ \t]+(default|[1-9][0-9]*)[ \t;]*$",
REG_EXTENDED | REG_ICASE)) {
strtok(command, " \t"); strtok(command, " \t");
strtok(NULL, " \t"); strtok(NULL, " \t");
char* p = strtok(NULL, " \t"); char *p = strtok(NULL, " \t");
if (strcasecmp(p, "default") == 0) { if (strcasecmp(p, "default") == 0) {
tsMaxBinaryDisplayWidth = DEFAULT_MAX_BINARY_DISPLAY_WIDTH; tsMaxBinaryDisplayWidth = DEFAULT_MAX_BINARY_DISPLAY_WIDTH;
} else { } else {
...@@ -202,8 +199,7 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) { ...@@ -202,8 +199,7 @@ static int32_t shellRunSingleCommand(TAOS *con, char *command) {
return 0; return 0;
} }
int32_t shellRunCommand(TAOS *con, char *command) {
int32_t shellRunCommand(TAOS* con, char* command) {
/* If command is empty just return */ /* If command is empty just return */
if (isEmptyCommand(command)) { if (isEmptyCommand(command)) {
return 0; return 0;
...@@ -255,7 +251,7 @@ int32_t shellRunCommand(TAOS* con, char* command) { ...@@ -255,7 +251,7 @@ int32_t shellRunCommand(TAOS* con, char* command) {
if (c == '\\') { if (c == '\\') {
if (quote != 0 && (*command == '_' || *command == '\\')) { if (quote != 0 && (*command == '_' || *command == '\\')) {
//DO nothing // DO nothing
} else { } else {
esc = true; esc = true;
continue; continue;
...@@ -284,21 +280,22 @@ int32_t shellRunCommand(TAOS* con, char* command) { ...@@ -284,21 +280,22 @@ int32_t shellRunCommand(TAOS* con, char* command) {
return shellRunSingleCommand(con, cmd); return shellRunSingleCommand(con, cmd);
} }
void freeResultWithRid(int64_t rid) { void freeResultWithRid(int64_t rid) {
#if 0
SSqlObj* pSql = taosAcquireRef(tscObjRef, rid); SSqlObj* pSql = taosAcquireRef(tscObjRef, rid);
if(pSql){ if(pSql){
taos_free_result(pSql); taos_free_result(pSql);
taosReleaseRef(tscObjRef, rid); taosReleaseRef(tscObjRef, rid);
} }
#endif
} }
void shellRunCommandOnServer(TAOS *con, char command[]) { void shellRunCommandOnServer(TAOS *con, char command[]) {
int64_t st, et; int64_t st, et;
wordexp_t full_path; wordexp_t full_path;
char * sptr = NULL; char *sptr = NULL;
char * cptr = NULL; char *cptr = NULL;
char * fname = NULL; char *fname = NULL;
bool printMode = false; bool printMode = false;
if ((sptr = strstr(command, ">>")) != NULL) { if ((sptr = strstr(command, ">>")) != NULL) {
...@@ -327,7 +324,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) { ...@@ -327,7 +324,7 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
st = taosGetTimestampUs(); st = taosGetTimestampUs();
TAOS_RES* pSql = taos_query_h(con, command, &result); TAOS_RES *pSql = taos_query(con, command);
if (taos_errno(pSql)) { if (taos_errno(pSql)) {
taos_error(pSql, st); taos_error(pSql, st);
return; return;
...@@ -344,7 +341,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) { ...@@ -344,7 +341,8 @@ void shellRunCommandOnServer(TAOS *con, char command[]) {
return; return;
} }
if (!tscIsUpdateQuery(pSql)) { // select and show kinds of commands TAOS_FIELD* pFields = taos_fetch_fields(pSql);
if (pFields != NULL) { // select and show kinds of commands
int error_no = 0; int error_no = 0;
int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode); int numOfRows = shellDumpResult(pSql, fname, &error_no, printMode);
...@@ -405,8 +403,7 @@ int regex_match(const char *s, const char *reg, int cflags) { ...@@ -405,8 +403,7 @@ int regex_match(const char *s, const char *reg, int cflags) {
return 0; return 0;
} }
static char *formatTimestamp(char *buf, int64_t val, int precision) {
static char* formatTimestamp(char* buf, int64_t val, int precision) {
if (args.is_raw_time) { if (args.is_raw_time) {
sprintf(buf, "%" PRId64, val); sprintf(buf, "%" PRId64, val);
return buf; return buf;
...@@ -425,7 +422,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { ...@@ -425,7 +422,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
ms = val % 1000; ms = val % 1000;
} }
/* comment out as it make testcases like select_with_tags.sim fail. /* comment out as it make testcases like select_with_tags.sim fail.
but in windows, this may cause the call to localtime crash if tt < 0, but in windows, this may cause the call to localtime crash if tt < 0,
need to find a better solution. need to find a better solution.
if (tt < 0) { if (tt < 0) {
...@@ -447,7 +444,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { ...@@ -447,7 +444,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
} }
} }
struct tm* ptm = localtime(&tt); struct tm *ptm = localtime(&tt);
size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", ptm); size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", ptm);
if (precision == TSDB_TIME_PRECISION_NANO) { if (precision == TSDB_TIME_PRECISION_NANO) {
...@@ -461,8 +458,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) { ...@@ -461,8 +458,7 @@ static char* formatTimestamp(char* buf, int64_t val, int precision) {
return buf; return buf;
} }
static void dumpFieldToFile(FILE *fp, const char *val, TAOS_FIELD *field, int32_t length, int precision) {
static void dumpFieldToFile(FILE* fp, const char* val, TAOS_FIELD* field, int32_t length, int precision) {
if (val == NULL) { if (val == NULL) {
fprintf(fp, "%s", TSDB_DATA_NULL_STR); fprintf(fp, "%s", TSDB_DATA_NULL_STR);
return; return;
...@@ -498,7 +494,7 @@ static void dumpFieldToFile(FILE* fp, const char* val, TAOS_FIELD* field, int32_ ...@@ -498,7 +494,7 @@ static void dumpFieldToFile(FILE* fp, const char* val, TAOS_FIELD* field, int32_
fprintf(fp, "\'%s\'", buf); fprintf(fp, "\'%s\'", buf);
break; break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
formatTimestamp(buf, *(int64_t*)val, precision); formatTimestamp(buf, *(int64_t *)val, precision);
fprintf(fp, "'%s'", buf); fprintf(fp, "'%s'", buf);
break; break;
default: default:
...@@ -506,7 +502,7 @@ static void dumpFieldToFile(FILE* fp, const char* val, TAOS_FIELD* field, int32_ ...@@ -506,7 +502,7 @@ static void dumpFieldToFile(FILE* fp, const char* val, TAOS_FIELD* field, int32_
} }
} }
static int dumpResultToFile(const char* fname, TAOS_RES* tres) { static int dumpResultToFile(const char *fname, TAOS_RES *tres) {
TAOS_ROW row = taos_fetch_row(tres); TAOS_ROW row = taos_fetch_row(tres);
if (row == NULL) { if (row == NULL) {
return 0; return 0;
...@@ -519,7 +515,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) { ...@@ -519,7 +515,7 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) {
return -1; return -1;
} }
FILE* fp = fopen(full_path.we_wordv[0], "w"); FILE *fp = fopen(full_path.we_wordv[0], "w");
if (fp == NULL) { if (fp == NULL) {
fprintf(stderr, "ERROR: failed to open file: %s\n", full_path.we_wordv[0]); fprintf(stderr, "ERROR: failed to open file: %s\n", full_path.we_wordv[0]);
wordfree(&full_path); wordfree(&full_path);
...@@ -542,18 +538,18 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) { ...@@ -542,18 +538,18 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) {
int numOfRows = 0; int numOfRows = 0;
do { do {
int32_t* length = taos_fetch_lengths(tres); int32_t *length = taos_fetch_lengths(tres);
for (int i = 0; i < num_fields; i++) { for (int i = 0; i < num_fields; i++) {
if (i > 0) { if (i > 0) {
fputc(',', fp); fputc(',', fp);
} }
dumpFieldToFile(fp, (const char*)row[i], fields +i, length[i], precision); dumpFieldToFile(fp, (const char *)row[i], fields + i, length[i], precision);
} }
fputc('\n', fp); fputc('\n', fp);
numOfRows++; numOfRows++;
row = taos_fetch_row(tres); row = taos_fetch_row(tres);
} while( row != NULL); } while (row != NULL);
result = 0; result = 0;
fclose(fp); fclose(fp);
...@@ -561,7 +557,6 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) { ...@@ -561,7 +557,6 @@ static int dumpResultToFile(const char* fname, TAOS_RES* tres) {
return numOfRows; return numOfRows;
} }
static void shellPrintNChar(const char *str, int length, int width) { static void shellPrintNChar(const char *str, int length, int width) {
wchar_t tail[3]; wchar_t tail[3];
int pos = 0, cols = 0, totalCols = 0, tailLen = 0; int pos = 0, cols = 0, totalCols = 0, tailLen = 0;
...@@ -625,8 +620,7 @@ static void shellPrintNChar(const char *str, int length, int width) { ...@@ -625,8 +620,7 @@ static void shellPrintNChar(const char *str, int length, int width) {
} }
} }
static void printField(const char *val, TAOS_FIELD *field, int width, int32_t length, int precision) {
static void printField(const char* val, TAOS_FIELD* field, int width, int32_t length, int precision) {
if (val == NULL) { if (val == NULL) {
int w = width; int w = width;
if (field->type < TSDB_DATA_TYPE_TINYINT || field->type > TSDB_DATA_TYPE_DOUBLE) { if (field->type < TSDB_DATA_TYPE_TINYINT || field->type > TSDB_DATA_TYPE_DOUBLE) {
...@@ -679,7 +673,7 @@ static void printField(const char* val, TAOS_FIELD* field, int width, int32_t le ...@@ -679,7 +673,7 @@ static void printField(const char* val, TAOS_FIELD* field, int width, int32_t le
shellPrintNChar(val, length, width); shellPrintNChar(val, length, width);
break; break;
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
formatTimestamp(buf, *(int64_t*)val, precision); formatTimestamp(buf, *(int64_t *)val, precision);
printf("%s", buf); printf("%s", buf);
break; break;
default: default:
...@@ -687,19 +681,18 @@ static void printField(const char* val, TAOS_FIELD* field, int width, int32_t le ...@@ -687,19 +681,18 @@ static void printField(const char* val, TAOS_FIELD* field, int width, int32_t le
} }
} }
bool isSelectQuery(TAOS_RES *tres) {
bool isSelectQuery(TAOS_RES* tres) { #if 0
char *sql = tscGetSqlStr(tres); char *sql = tscGetSqlStr(tres);
if (regex_match(sql, "^[\t ]*select[ \t]*", REG_EXTENDED | REG_ICASE)) { if (regex_match(sql, "^[\t ]*select[ \t]*", REG_EXTENDED | REG_ICASE)) {
return true; return true;
} }
#endif
return false; return false;
} }
static int verticalPrintResult(TAOS_RES *tres) {
static int verticalPrintResult(TAOS_RES* tres) {
TAOS_ROW row = taos_fetch_row(tres); TAOS_ROW row = taos_fetch_row(tres);
if (row == NULL) { if (row == NULL) {
return 0; return 0;
...@@ -719,7 +712,7 @@ static int verticalPrintResult(TAOS_RES* tres) { ...@@ -719,7 +712,7 @@ static int verticalPrintResult(TAOS_RES* tres) {
uint64_t resShowMaxNum = UINT64_MAX; uint64_t resShowMaxNum = UINT64_MAX;
if (args.commands == NULL && args.file[0] == 0 && isSelectQuery(tres) && !tscIsQueryWithLimit(tres)) { if (args.commands == NULL && args.file[0] == 0 && isSelectQuery(tres) /*&& !tscIsQueryWithLimit(tres)*/) {
resShowMaxNum = DEFAULT_RES_SHOW_NUM; resShowMaxNum = DEFAULT_RES_SHOW_NUM;
} }
...@@ -729,15 +722,15 @@ static int verticalPrintResult(TAOS_RES* tres) { ...@@ -729,15 +722,15 @@ static int verticalPrintResult(TAOS_RES* tres) {
if (numOfRows < resShowMaxNum) { if (numOfRows < resShowMaxNum) {
printf("*************************** %d.row ***************************\n", numOfRows + 1); printf("*************************** %d.row ***************************\n", numOfRows + 1);
int32_t* length = taos_fetch_lengths(tres); int32_t *length = taos_fetch_lengths(tres);
for (int i = 0; i < num_fields; i++) { for (int i = 0; i < num_fields; i++) {
TAOS_FIELD* field = fields + i; TAOS_FIELD *field = fields + i;
int padding = (int)(maxColNameLen - strlen(field->name)); int padding = (int)(maxColNameLen - strlen(field->name));
printf("%*.s%s: ", padding, " ", field->name); printf("%*.s%s: ", padding, " ", field->name);
printField((const char*)row[i], field, 0, length[i], precision); printField((const char *)row[i], field, 0, length[i], precision);
putchar('\n'); putchar('\n');
} }
} else if (showMore) { } else if (showMore) {
...@@ -748,12 +741,12 @@ static int verticalPrintResult(TAOS_RES* tres) { ...@@ -748,12 +741,12 @@ static int verticalPrintResult(TAOS_RES* tres) {
numOfRows++; numOfRows++;
row = taos_fetch_row(tres); row = taos_fetch_row(tres);
} while(row != NULL); } while (row != NULL);
return numOfRows; return numOfRows;
} }
static int calcColWidth(TAOS_FIELD* field, int precision) { static int calcColWidth(TAOS_FIELD *field, int precision) {
int width = (int)strlen(field->name); int width = (int)strlen(field->name);
switch (field->type) { switch (field->type) {
...@@ -801,7 +794,8 @@ static int calcColWidth(TAOS_FIELD* field, int precision) { ...@@ -801,7 +794,8 @@ static int calcColWidth(TAOS_FIELD* field, int precision) {
case TSDB_DATA_TYPE_TIMESTAMP: case TSDB_DATA_TYPE_TIMESTAMP:
if (args.is_raw_time) { if (args.is_raw_time) {
return MAX(14, width); return MAX(14, width);
} if (precision == TSDB_TIME_PRECISION_NANO) { }
if (precision == TSDB_TIME_PRECISION_NANO) {
return MAX(29, width); return MAX(29, width);
} else if (precision == TSDB_TIME_PRECISION_MICRO) { } else if (precision == TSDB_TIME_PRECISION_MICRO) {
return MAX(26, width); // '2020-01-01 00:00:00.000000' return MAX(26, width); // '2020-01-01 00:00:00.000000'
...@@ -816,11 +810,10 @@ static int calcColWidth(TAOS_FIELD* field, int precision) { ...@@ -816,11 +810,10 @@ static int calcColWidth(TAOS_FIELD* field, int precision) {
return 0; return 0;
} }
static void printHeader(TAOS_FIELD *fields, int *width, int num_fields) {
static void printHeader(TAOS_FIELD* fields, int* width, int num_fields) {
int rowWidth = 0; int rowWidth = 0;
for (int col = 0; col < num_fields; col++) { for (int col = 0; col < num_fields; col++) {
TAOS_FIELD* field = fields + col; TAOS_FIELD *field = fields + col;
int padding = (int)(width[col] - strlen(field->name)); int padding = (int)(width[col] - strlen(field->name));
int left = padding / 2; int left = padding / 2;
printf(" %*.s%s%*.s |", left, " ", field->name, padding - left, " "); printf(" %*.s%s%*.s |", left, " ", field->name, padding - left, " ");
...@@ -834,8 +827,7 @@ static void printHeader(TAOS_FIELD* fields, int* width, int num_fields) { ...@@ -834,8 +827,7 @@ static void printHeader(TAOS_FIELD* fields, int* width, int num_fields) {
putchar('\n'); putchar('\n');
} }
static int horizontalPrintResult(TAOS_RES *tres) {
static int horizontalPrintResult(TAOS_RES* tres) {
TAOS_ROW row = taos_fetch_row(tres); TAOS_ROW row = taos_fetch_row(tres);
if (row == NULL) { if (row == NULL) {
return 0; return 0;
...@@ -854,7 +846,7 @@ static int horizontalPrintResult(TAOS_RES* tres) { ...@@ -854,7 +846,7 @@ static int horizontalPrintResult(TAOS_RES* tres) {
uint64_t resShowMaxNum = UINT64_MAX; uint64_t resShowMaxNum = UINT64_MAX;
if (args.commands == NULL && args.file[0] == 0 && isSelectQuery(tres) && !tscIsQueryWithLimit(tres)) { if (args.commands == NULL && args.file[0] == 0 && isSelectQuery(tres) /* && !tscIsQueryWithLimit(tres)*/) {
resShowMaxNum = DEFAULT_RES_SHOW_NUM; resShowMaxNum = DEFAULT_RES_SHOW_NUM;
} }
...@@ -862,11 +854,11 @@ static int horizontalPrintResult(TAOS_RES* tres) { ...@@ -862,11 +854,11 @@ static int horizontalPrintResult(TAOS_RES* tres) {
int showMore = 1; int showMore = 1;
do { do {
int32_t* length = taos_fetch_lengths(tres); int32_t *length = taos_fetch_lengths(tres);
if (numOfRows < resShowMaxNum) { if (numOfRows < resShowMaxNum) {
for (int i = 0; i < num_fields; i++) { for (int i = 0; i < num_fields; i++) {
putchar(' '); putchar(' ');
printField((const char*)row[i], fields + i, width[i], length[i], precision); printField((const char *)row[i], fields + i, width[i], length[i], precision);
putchar(' '); putchar(' ');
putchar('|'); putchar('|');
} }
...@@ -879,17 +871,16 @@ static int horizontalPrintResult(TAOS_RES* tres) { ...@@ -879,17 +871,16 @@ static int horizontalPrintResult(TAOS_RES* tres) {
numOfRows++; numOfRows++;
row = taos_fetch_row(tres); row = taos_fetch_row(tres);
} while(row != NULL); } while (row != NULL);
return numOfRows; return numOfRows;
} }
int shellDumpResult(TAOS_RES *tres, char *fname, int *error_no, bool vertical) { int shellDumpResult(TAOS_RES *tres, char *fname, int *error_no, bool vertical) {
int numOfRows = 0; int numOfRows = 0;
if (fname != NULL) { if (fname != NULL) {
numOfRows = dumpResultToFile(fname, tres); numOfRows = dumpResultToFile(fname, tres);
} else if(vertical) { } else if (vertical) {
numOfRows = verticalPrintResult(tres); numOfRows = verticalPrintResult(tres);
} else { } else {
numOfRows = horizontalPrintResult(tres); numOfRows = horizontalPrintResult(tres);
...@@ -899,13 +890,12 @@ int shellDumpResult(TAOS_RES *tres, char *fname, int *error_no, bool vertical) { ...@@ -899,13 +890,12 @@ int shellDumpResult(TAOS_RES *tres, char *fname, int *error_no, bool vertical) {
return numOfRows; return numOfRows;
} }
void read_history() { void read_history() {
// Initialize history // Initialize history
memset(history.hist, 0, sizeof(char *) * MAX_HISTORY_SIZE); memset(history.hist, 0, sizeof(char *) * MAX_HISTORY_SIZE);
history.hstart = 0; history.hstart = 0;
history.hend = 0; history.hend = 0;
char * line = NULL; char *line = NULL;
size_t line_size = 0; size_t line_size = 0;
int read_size = 0; int read_size = 0;
...@@ -975,9 +965,9 @@ int isCommentLine(char *line) { ...@@ -975,9 +965,9 @@ int isCommentLine(char *line) {
void source_file(TAOS *con, char *fptr) { void source_file(TAOS *con, char *fptr) {
wordexp_t full_path; wordexp_t full_path;
int read_len = 0; int read_len = 0;
char * cmd = calloc(1, tsMaxSQLStringLen+1); char *cmd = calloc(1, tsMaxSQLStringLen + 1);
size_t cmd_len = 0; size_t cmd_len = 0;
char * line = NULL; char *line = NULL;
size_t line_len = 0; size_t line_len = 0;
if (wordexp(fptr, &full_path, 0) != 0) { if (wordexp(fptr, &full_path, 0) != 0) {
...@@ -1087,5 +1077,5 @@ void shellGetGrantInfo(void *con) { ...@@ -1087,5 +1077,5 @@ void shellGetGrantInfo(void *con) {
} }
fprintf(stdout, "\n"); fprintf(stdout, "\n");
#endif #endif
} }
...@@ -19,7 +19,11 @@ ...@@ -19,7 +19,11 @@
#include "shell.h" #include "shell.h"
#include "shellCommand.h" #include "shellCommand.h"
#include "tkey.h" #include "tkey.h"
#include "tulog.h" #include "ulog.h"
#include <wordexp.h>
#include <argp.h>
#include <termio.h>
#define OPT_ABORT 1 /* �Cabort */ #define OPT_ABORT 1 /* �Cabort */
...@@ -68,7 +72,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { ...@@ -68,7 +72,6 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
break; break;
case 'P': case 'P':
if (arg) { if (arg) {
tsDnodeShellPort = atoi(arg);
arguments->port = atoi(arg); arguments->port = atoi(arg);
} else { } else {
fprintf(stderr, "Invalid port\n"); fprintf(stderr, "Invalid port\n");
...@@ -216,7 +219,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) { ...@@ -216,7 +219,9 @@ void shellParseArgument(int argc, char *argv[], SShellArguments *arguments) {
argp_parse(&argp, argc, argv, 0, 0, arguments); argp_parse(&argp, argc, argv, 0, 0, arguments);
if (arguments->abort) { if (arguments->abort) {
#ifndef _ALPINE #ifndef _ALPINE
#if 0
error(10, 0, "ABORTED"); error(10, 0, "ABORTED");
#endif
#else #else
abort(); abort();
#endif #endif
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "os.h" #include "os.h"
#include "shell.h" #include "shell.h"
#include "tconfig.h" #include "tconfig.h"
#include "tnettest.h" #include "tglobal.h"
pthread_t pid; pthread_t pid;
static tsem_t cancelSem; static tsem_t cancelSem;
...@@ -28,21 +28,25 @@ void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) { ...@@ -28,21 +28,25 @@ void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) {
void *cancelHandler(void *arg) { void *cancelHandler(void *arg) {
setThreadName("cancelHandler"); setThreadName("cancelHandler");
while(1) { while (1) {
if (tsem_wait(&cancelSem) != 0) { if (tsem_wait(&cancelSem) != 0) {
taosMsleep(10); taosMsleep(10);
continue; continue;
} }
#ifdef LINUX #ifdef LINUX
#if 0
int64_t rid = atomic_val_compare_exchange_64(&result, result, 0); int64_t rid = atomic_val_compare_exchange_64(&result, result, 0);
SSqlObj* pSql = taosAcquireRef(tscObjRef, rid); SSqlObj* pSql = taosAcquireRef(tscObjRef, rid);
taos_stop_query(pSql); taos_stop_query(pSql);
taosReleaseRef(tscObjRef, rid); taosReleaseRef(tscObjRef, rid);
#endif
#else #else
printf("\nReceive ctrl+c or other signal, quit shell.\n"); printf("\nReceive ctrl+c or other signal, quit shell.\n");
exit(0); exit(0);
#endif #endif
printf("\nReceive ctrl+c or other signal, quit shell.\n");
exit(0);
} }
return NULL; return NULL;
...@@ -69,8 +73,7 @@ int checkVersion() { ...@@ -69,8 +73,7 @@ int checkVersion() {
} }
// Global configurations // Global configurations
SShellArguments args = { SShellArguments args = {.host = NULL,
.host = NULL,
#ifndef TD_WINDOWS #ifndef TD_WINDOWS
.password = NULL, .password = NULL,
#endif #endif
...@@ -87,13 +90,12 @@ SShellArguments args = { ...@@ -87,13 +90,12 @@ SShellArguments args = {
.pktLen = 1000, .pktLen = 1000,
.pktNum = 100, .pktNum = 100,
.pktType = "TCP", .pktType = "TCP",
.netTestRole = NULL .netTestRole = NULL};
};
/* /*
* Main function. * Main function.
*/ */
int main(int argc, char* argv[]) { int main(int argc, char *argv[]) {
/*setlocale(LC_ALL, "en_US.UTF-8"); */ /*setlocale(LC_ALL, "en_US.UTF-8"); */
if (!checkVersion()) { if (!checkVersion()) {
...@@ -102,6 +104,7 @@ int main(int argc, char* argv[]) { ...@@ -102,6 +104,7 @@ int main(int argc, char* argv[]) {
shellParseArgument(argc, argv, &args); shellParseArgument(argc, argv, &args);
#if 0
if (args.dump_config) { if (args.dump_config) {
taosInitGlobalCfg(); taosInitGlobalCfg();
taosReadGlobalLogCfg(); taosReadGlobalLogCfg();
...@@ -123,9 +126,10 @@ int main(int argc, char* argv[]) { ...@@ -123,9 +126,10 @@ int main(int argc, char* argv[]) {
taosNetTest(args.netTestRole, args.host, args.port, args.pktLen, args.pktNum, args.pktType); taosNetTest(args.netTestRole, args.host, args.port, args.pktLen, args.pktNum, args.pktType);
exit(0); exit(0);
} }
#endif
/* Initialize the shell */ /* Initialize the shell */
TAOS* con = shellInit(&args); TAOS *con = shellInit(&args);
if (con == NULL) { if (con == NULL) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册